akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int dp[21][51][51];

int main() {
	int n; cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (; s[i].length() < 20; s[i].push_back('`'));
	}
	for (int i = 0; i < n; i++)
		dp[20][i][i + 1] = 1;
	for (int j = 19; j >= 0; j--) {
		for (int l = 0; l <= n; l++) {
			vector<vector<int> > a(n + 1, vector<int>(28));
			a[l][0] = 1;
			for (int i = l; i <= n; i++)
				for (int k = 0; k < 27; k++) {
					a[i][k + 1] = (a[i][k + 1] + a[i][k]) % MOD;
					for (int _i = i; _i < n; _i++) {
						char c = s[_i][j];
						if (c == '`' + k || (k && c == '?'));
						else break;
						a[_i + 1][k + 1] = (a[_i + 1][k + 1] + (ll)a[i][k] * dp[j + 1][i][_i + 1]) % MOD;
						dp[j][l][_i + 1] = (dp[j][l][_i + 1] + (ll)a[i][k] * dp[j + 1][i][_i + 1]) % MOD;
					}
				}
		}
	}
	cout << dp[0][0][n] << endl;
}

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

int main(){
  long s, a, min = 1000;
  int hoge[10];
  int cnt = 0;
  std::cin >> s;
  while(s % 10 != 0){
    hoge[cnt] = s % 10;
    s = (s - (s % 10)) / 10;
    cnt++;
  }
  for(int i = 0; i < cnt - 2; i++){
    a = abs(hoge[i + 2] * 100 + hoge[i + 1] * 10 + hoge[i] - 753);
    min = std::min(min, a);
  }
  std::cout << min << std::endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

long long solve(long long N) {
    auto pf = prime_factorize(N);
    long long res = 0;
    for (auto p : pf) {
        long long n = p.second;
        //COUT(n);
        long long tmp = 0, cur = 1;
        while (n >= cur) n -= cur++, ++tmp;

        //cout << n << ": " << tmp << endl;
        res += tmp;
    }
    return res;
}

int main() {
    long long N;
    while (cin >> N) cout << solve(N) << endl;
}

















Measured memory_bytes: 3632
use std::cmp;

const INF: u32 = 1 << 30;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc
        .read::<String>()
        .chars()
        .map(|c| c as usize - 'a' as usize)
        .collect::<Vec<_>>();

    let mut prefix_dp = vec![INF; 1 << 26];
    let mut cur: usize = 0;
    for s in s.into_iter() {
        cur ^= 1 << s;
        if cur.count_ones() <= 1 {
            prefix_dp[cur] = 1;
            continue;
        }

        let mut min = prefix_dp[cur] + 1;
        for i in 0..26 {
            let suffix = 1 << i;
            min = cmp::min(min, prefix_dp[cur ^ suffix] + 1);
        }
        prefix_dp[cur] = min;
    }

    println!("{}", prefix_dp[cur]);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 268668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n,k;
	cin >> n >> k;
	int ans = 1;
	for(int i = 0;i<n;i++)
	ans *= k-(i>0);
	cout<<ans<<endl;
	return 0;
}

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

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 1005;
const int MOD = 1e9+7;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};

int dp[MAX][MAX];

int main()
{
//    READ;
//    WRITE;
    int n, m; sii(n, m);
    char arr[n][m];

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            cin >> arr[i][j];

    for(int i=1; i<n; i++){
        if(arr[i][0] == '#')
            break;
        dp[i][0] = 1;
    }
    for(int j=1; j<m; j++){
        if(arr[0][j] == '#')
            break;
        dp[0][j] = 1;
    }

    for(int i=1; i<n; i++){
        for(int j=1; j<m; j++){
            if(arr[i][j] != '#')
                dp[i][j] = (dp[i][j-1] % MOD + dp[i-1][j] % MOD) % MOD;
        }
    }

    cout << dp[n-1][m-1] << endl;

    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
int main() {
	string s;
	set<string> st;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		st.insert(s);
	}

	cout << st.size() << endl;

}


Measured memory_bytes: 19128
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
#define _USE_MATH_DEFINES
using namespace std;
using namespace std::chrono;


int mod_power(int x, int y, int mod){
  int ans = 1;
  x %= mod;
  while(y){
    if (y & 1)
      ans *= x, ans %= mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}

int mod_inverse(int n, int mod){
  return mod_power(n, mod - 2, mod);
}

int mod_ncr(int n, int r, int mod){
  if (r == 0 or r == n)
    return 1;
  int fact = 1;
  for (int i = 1; i <= r; i++)
    fact *= i, fact %= mod;
  int ans = 1;
  for (int i = n; i > n - r; i--)
    ans *= i, ans %= mod;
  ans *= mod_inverse(fact, mod), ans %= mod;
  return ans;
}

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}


signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);

  int n, k;
  int mod = 1e9 + 7;
  cin >> n >> k;
  for (int i = 1; i <= k; i++){
    cout << (mod_ncr(n - k + 1, i, mod) * mod_ncr(k - 1, i - 1, mod)) % mod << endl;
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  string s, t;
  cin >> s >> t;
  if(s == t.substr(0, t.size()-1)) cout << "Yes\n";
  else cout << "No\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3580
n = gets.chomp.to_i

nums = [0, 3, 5, 7]

def to_n(s, nums)
  s.chars.map { |i| nums[i.to_i] }.join.to_i
end

count = 0
1.upto(4 ** n.to_s.length) do |i|
  s = i.to_s(4)
  break if to_n(s, nums) > n
  next if s.include?('0')
  next unless s.include?('1') && s.include?('2') && s.include?('3')
  count += 1
end
puts count


Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h)cin>> s[i];
    bool flag = 1;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                bool flag2 = 0;
                if(i-1>=0){
                    if(s[i-1][j]=='#'){
                        flag2 = 1;
                    }
                }
                if(j-1>=0){
                    if(s[i][j-1]=='#'){
                        flag2 = 1;
                    }
                }
                if(i+1<h){
                    if(s[i+1][j]=='#'){
                        flag2 = 1;
                    }
                }
                if(j+1<w){
                    if(s[i][j+1]=='#'){
                        flag2 = 1;
                    }
                }
                if(!flag2){
                    flag = 0;
                }
            }
            
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

using i64 = int64_t;

int main(){
    i64 n, t;
    cin >> n >> t;
    i64 ans = 0, before = 0;
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        if(i==0)continue;
        ans += min(t, tmp-before);
        before = tmp;
    }
    ans += t;
    cout << ans << endl;

    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

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

int main() {
  u32 N, K;
  cin >> N >> K;

  vector<u64> P(N);
  for (u32 i = 0; i < N; ++i) {
    u64 p;
    cin >> p;
    P[i] = (p + 1);
  }
  vector<u64> K_res(N - K + 1, 0);
  double tmp_res = 0;
  for (u32 i = 0; i < K; ++i) tmp_res += P[i];
  K_res[0] = tmp_res;
  for (u32 i = K; i < N; ++i) {
    tmp_res -= P[i - K];
    tmp_res += P[i];
    K_res[i - K + 1] = tmp_res;
  }
  cout << setprecision(15)
       << (double)(*max_element(K_res.begin(), K_res.end()) * 5) / 10 << endl;

  return 0;
}

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

int n;
long long s[405];
long long dp[405][405];

int main(){

    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>s[i],s[i]+=s[i-1];

    for(int i=0;i<=n-1;i++)
        for(int j=i+1;j<=n;j++)
            dp[i][j]=~(1LL<<63);

    for(int i=n-1;i>=1;i--)
        for(int j=i+1;j<=n;j++)
            for(int k=i;k<=j-1;k++)
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+s[j]-s[i-1]);

    cout<<dp[1][n];

}


Measured memory_bytes: 1536
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] -= 1
    pt = [0] * n
    q = [[0, i] for i in range(n)]
    q = collections.deque(q)
    now = 0
    fq = collections.defaultdict(int)
    md = 0
    while True:
        if len(q) != 0:
            d, p = q.popleft()
            if d == now:
                o = a[p][pt[p]]
                r = a[o][pt[o]]
                if p == r and p not in fq and o not in fq:
                    fq[p]
                    fq[o]
                    md = max(md, d)
                    if len(a[p]) > pt[p] + 1:
                        pt[p] += 1
                        q.append([d + 1, p])
                    if len(a[o]) > pt[o] + 1:
                        pt[o] += 1
                        q.append([d + 1, o])
            else:
                q.append([d, p])
                fq = collections.defaultdict(int)
                now += 1
        else:
            break
    print(md + 1 if sum(pt) == (n - 2) * n else -1)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 72284
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;

ll N,A,B;
int main(){
    cin>>N>>A>>B;
    ll ans = N/(A+B)*A;
    ll tail = N%(A+B);
    if(tail<=A) ans += tail;
    else ans += A;
    cout<<ans<<endl;
    return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int X, Y, Z;
    std::cin >> X >> Y >> Z;

    int ans = 0;
    X -= Z;
    while(true) {
        X -= Y;
        X -= Z;
        if(X < 0) {
            break;
        }
        else {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.algorithm, std.typecons;

void main(){

	alias Tuple!(int, "x", int, "y") Point;
	int W, H, N;
	auto input = readln.split.map!(to!int);
	W = input[0], H = input[1], N = input[2];
	int total;
	Point before;
	foreach (i; 0..N) {
		input = readln.split.map!(to!int);
		Point p;
		p.x = input[0], p.y = input[1];
		if (i > 0) {
			int dx = p.x - before.x, dy = p.y - before.y;
			if (dx * dy > 0) {
				dx = dx > 0 ? dx : -dx;
				dy = dy > 0 ? dy : -dy;
				total += max(dx, dy);
			} else {
				dx = dx > 0 ? dx : -dx;
				dy = dy > 0 ? dy : -dy;
				total += dx + dy;
			}
		}
		before = p;
	}
	total.writeln;
}

Measured memory_bytes: 2512
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr 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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

template<typename T>
struct LCA{
	const int LOG_N;
	vector<int> depth;//根からの深さ
	vector<vector<T>> g;
	vector<vector<int>> dp;//dp[i][j]:2^i回たどって到達する頂点
	bool flag;

	LCA(vector<vector<T>> &g):g(g),depth(g.size()),LOG_N(log2(g.size())+1){
		dp.assign(LOG_N, vector<int>(g.size(), -1));
		flag = false;
	}

	void dfs(int v,int p,int d){
		dp[0][v] = p;
		depth[v] = d;
		for(auto to:g[v]){
			if(to!=p){
				dfs(to, v, d + 1);
			}
		}
	}

	void init(int root=0){
		flag = true;
		dfs(root, -1, 0);
		for (int k = 0; k + 1 < LOG_N;++k){
			for (int i = 0; i < dp[0].size();++i){
				if(dp[k][i]==-1){
					dp[k + 1][i] = -1;
				}
				else{
					dp[k + 1][i] = dp[k][dp[k][i]];
				}
			}
		}
	}

	int query(int u,int v){
		assert(flag);
		if (depth[u] > depth[v])
		{
			swap(u, v);
		}
		for (int i = LOG_N - 1; i >= 0;--i){
			if(((depth[v]-depth[u])>>i)&1)
				v = dp[i][v];
		}
		if(u==v)
			return u;
		for (int i = LOG_N - 1; i >= 0;--i){
			if(dp[i][u]!=dp[i][v]){
				u = dp[i][u];
				v = dp[i][v];
			}
		}
		return dp[0][u];
	}
};

void solve()
{
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	rep(i,n){
		int k;
		cin >> k;
		rep(j,k){
			int c;
			cin >> c;
			g[i].pb(c);
		}
	}
	LCA<int> lca(g);
	lca.init();
	int q;
	cin >> q;
	rep(i,q){
		int u, v;
		cin >> u >> v;
		cout << lca.query(u, v) << "\n";
	}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


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

N = int(readline())
A = list(map(int, readline().split()))
S = A[0] + A[1]
X = 0
for i in range(2, N):
    X ^= A[i]

K = S-X
if K&1:
    print(-1)
else:
    K >>= 1
    if K&X or K > A[0]:
        print(-1)
    else:
        Y = 0
        for i in range(60, -1, -1):
            if X & (1<<i) and (Y+(1<<i))^K <= A[0]:
                Y += 1<<i
        Y = Y^K
        if not Y:
            print(-1)
        else:
            print(A[0]-Y)

Measured memory_bytes: 62244
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    //n**1/2を超えない自然数で割っていき、割り切れなかったら素数
    int n;
    cin>>n;
    int S{};
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        int b;
        int ss{};
        b=floor(sqrt(a));
        for(int s=b;1<s;s--)
        {
            if(a%s!=0)ss++;
        }
        if(ss==b-1)S++;
    }
    cout<<S<<endl;
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int  a=1, i = 0, j = 0, k = 0;
    char su;//0??????1??????2??????3??????
    cin >> a;
    int b[4][13];
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            b[i][j]=1;
            }
        }
    for(i=0;i<a;i++){
        cin >> su >> k;
        if(su=='S'){
            b[0][k-1]=0;//?????£??????0
            }
        if(su=='H'){
            b[1][k-1]=0;//?????£??????0
            }
        if(su=='C'){
            b[2][k-1]=0;//?????£??????0
            }
        if(su=='D'){
            b[3][k-1]=0;//?????£??????0
            }
        }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(b[i][j]==1){
                if(i==0){
                    cout << 'S' << ' ' << j+1 << endl;
                }
                if(i==1){
                    cout << 'H' << ' ' << j+1 << endl;
                }
                if(i==2){
                    cout << 'C' << ' ' << j+1 << endl;
                }
                if(i==3){
                    cout << 'D' << ' ' << j+1 << endl;
                }
            }
        }
    }

   // cout << endl;



}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[12345678], res[12345678];
signed main() {
	vector<char> v; map<int, int> cost;
	int n, m, a, b, c, x, ans = 0; string s, t; double cnt;
	cin >> n >> s;
	if (s.size() <= n) { cout << s << endl; }
	else {
		for (int h = 0; h < n; h++) {
			cout << s[h];
		}
		cout << "..." << endl;
	}
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> wa(n, 0);
  vector<ll> ac(n, 0);
  rep(i, m) {
    ll p;
    string s;
    cin >> p >> s;
    p--;
    if (ac[p] > 0) continue;
    if (s == "AC")
      ac[p] = 1;
    else
      wa[p]++;
  }
  rep(i, n) wa[i] *= ac[i];
  cout << accumulate(ALL(ac),0LL) << " " << accumulate(ALL(wa),0LL) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    vector<p> c;
    for(ll i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        c.push_back(p(b,a));
    }
    sort(c.begin(), c.end());
    bool ok = true;
    ll ans = 0;
    for(ll i =0; i < n; i++){
        //cout << c[i].first << " " << c[i].second << endl;
        ans+=c[i].second;
        if(ans > c[i].first)
            ok = false;
    }
    if(ok==true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 6384
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

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

const int N = 1e5 + 10; 
int n, a[N]; 

int main(int argc, char const *argv[]) {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) 
        scanf("%d", &a[i]); 

    int idx1 = 0; 
    for(int i = 1; i <= n; ++i) 
        if(a[i] > a[idx1]) idx1 = i; 

    int idx2 = 0; 
    for(int i = 1; i <= n; ++i) if(i != idx1) 
        if(abs(a[idx1] / 2 - a[i]) < 
           abs(a[idx1] / 2 - a[idx2])) idx2 = i;  

    printf("%d %d\n", a[idx1], a[idx2]); 
}

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

int main(){
	int i,x,sum,slen;
	char input[1024],num[2];
	while(1){
		sum=0;
		fgets(input,sizeof input,stdin);
		slen=strlen(input);
				for(i=0;i<slen-1;i++){
			num[0]=input[i];
			sum+=atoi(num);
		}
		if(sum==0){
			break;
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

Measured memory_bytes: 528
#include<iostream>
using namespace std;
 
long long n,k,x,y;
int main(){
	cin>>n>>k;
	if (k%2==0){
		x=n/k;y=n/k;
		if (n%k>=(k/2))y++;
	}else{
		x=n/k;y=0;
	}
	cout<<x*x*x+y*y*y<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n;
  cin>>n;
  map<ll,ll> mp;
  rep(i,n){
    ll a;
    cin>>a;
    mp[a]++;
  }
  vector<ll> b;
  for(auto x : mp){
    if(x.second>=2){
      b.push_back(x.first);
    }
    if(x.second>=4){
      b.push_back(x.first);
    }
  }
  if(b.size()<2){
    cout<<0<<endl;
  }
  else{
    cout<<b[b.size()-1]*b[b.size()-2];
  }
}


Measured memory_bytes: 9844
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n , m;
    cin >> n >> m;
    vector<int> A(n);
    int tot = 0;
    REP(i,n) {
        cin >>  A[i];
        tot += A[i];
    }
    
    double tmp = (double) tot / (double) (4*m);
    int ans = 0;
    REP(i,n) {
        if(A[i] >= tmp) {
            ans++;
        }
    }

    if(ans >= m) 
       cout << "Yes" << endl; 
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 16;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

ll gr(ll A, ll K) {
	if (A < K) return 0;
	if (A%K == 0) return A / K;

	ll x = A / K;

	ll t = x * K + 1;
	ll v = A - t;
	A -= (v / (x + 1) + 1) * (x + 1);
	return gr(A, K);
}
int main() {
	int N, i;

	ll G = 0;
	scanf("%d", &N);
	while (N--) {
		ll t1, t2;
		scanf("%lld %lld", &t1, &t2);
		G ^= gr(t1, t2);
	}
	if (G) printf("Takahashi\n");
	else printf("Aoki\n");
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
q=deque()
l=[]
for i in range(h):
  l.append(list(input()))
lb=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if l[i][j]=="#":
      q.append([i,j])
move=[[1,0],[-1,0],[0,1],[0,-1]]
count=0
b=True
q2=deque()
while b:
  while q:
    q1=q.popleft()
    x1=q1[0]
    y1=q1[1]
    for i in range(4):
      dx=move[i][0]
      dy=move[i][1]
      x=x1+dx
      y=y1+dy
      if x<0 or x>h-1 or y<0 or y>w-1:
        pass
      elif l[x][y]=="#":
        pass
      else:
        l[x][y]="#"
        q2.append([x,y])
  if len(q2)!=0:
    q=q2
    q2=deque()
    count+=1
  else:
    b=False
print(count)


Measured memory_bytes: 177756
// Grid 1.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
using namespace std;
const int G = 1000 + 10;
char a[G][G];
long long dp[G][G];

int main()
{
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> a[i][j];
		}
	}
	dp[0][0] = 1;
	for (int i = 1; i < w; i++){
		if (a[0][i] == '.'){
			dp[0][i] = dp[0][i-1];
			dp[0][i] %= 1000000007;
		}
	}
	for (int i = 1; i < h; i++){
		if (a[i][0] == '.'){
			dp[i][0] = dp[i-1][0];
			dp[i][0] %= 1000000007;
		}
	}
	for (int i = 1; i < h; i++){
		for (int j = 1; j < w; j++){
			if (a[i][j] == '.'){
				dp[i][j] = dp[i-1][j] + dp[i][j-1];
				dp[i][j] %= 1000000007;
			}
		}
	}
	cout << dp[h-1][w-1] % 1000000007 << endl;
	return 0;
}



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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int keta = s.size();
    vector<int> n_keta(keta);
    REP(i, keta) n_keta[i] = (int)(s[i] - '0');

    ll dp[keta][4][2];
    REP(i, keta) REP(j, 4) REP(k, 2) dp[i][j][k] = 0;
    dp[0][1][0] = 1;
    dp[0][1][1] = (int)n_keta[0] - 1;
    dp[0][0][1] = 1;

    REP(i, keta-1) {
        /* ぴったりからぴったり */
        if(n_keta[i+1] == 0) {
            REP(j, 4) dp[i+1][j][0] += dp[i][j][0];
        } else {
            REP(j, 3) dp[i+1][j+1][0] += dp[i][j][0];
        }

        /* ぴったりからより小さい */
        if(n_keta[i+1] != 0) {
            REP(j, 3) dp[i+1][j+1][1] += dp[i][j][0] * (n_keta[i+1] - 1);
            REP(j, 4) dp[i+1][j][1] += dp[i][j][0];
        }

        /* より小さいからより小さい */
        REP(j, 3) dp[i+1][j+1][1] += dp[i][j][1] * 9;
        REP(j, 4) dp[i+1][j][1] += dp[i][j][1];
    }

    cout << dp[keta-1][k][0] + dp[keta-1][k][1] << endl;

    return 0;
}

Measured memory_bytes: 256
N,C=map(int,input().split())
D=[]
for i in range(C):
    d=list(map(int,input().split()))
    D.append(d)
    
mod0=[0 for i in range(C)]
mod1=[0 for i in range(C)]
mod2=[0 for i in range(C)]

Arr=[]
for i in range(N):
    c=list(map(int,input().split()))
    Arr.append(c)
    
for i in range(N):
    for j in range(N):
        if (i+j)%3==0:
            mod0[Arr[i][j]-1]+=1
        elif (i+j)%3==1:
            mod1[Arr[i][j]-1]+=1
        elif (i+j)%3==2:
            mod2[Arr[i][j]-1]+=1

MOD0=[]
MOD1=[]
MOD2=[]

for i in range(C):
    cnt0=0
    cnt1=0
    cnt2=0
    for j in range(C):
        cnt0+=mod0[j]*D[j][i]
        cnt1+=mod1[j]*D[j][i]
        cnt2+=mod2[j]*D[j][i]
    MOD0.append(cnt0)
    MOD1.append(cnt1)
    MOD2.append(cnt2)
ans=10**15
for a in range(len(MOD0)):
    for b in range(len(MOD0)):
        for c in range(len(MOD0)):
            if a==b or b==c or c==a:
                pass
            else:
                if MOD0[a]+MOD1[b]+MOD2[c]<ans:
                    ans=MOD0[a]+MOD1[b]+MOD2[c]
print(ans)


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

int N, M;
vector<int>A, B;

map<pair<int, int>, pair<int, int>> DP[2][51][51][2];
map<pair<int, int>, bool> used[2][51][51][2];

pair<int, int> solve(int t, int a, int b, int ast, int bst, int as, int bs, int pass) {
	if (used[t][a][b][pass][make_pair(ast, bst)]) {
		pair<int, int>res;
		res.first = DP[t][a][b][pass][make_pair(ast, bst)].first + as;
		res.second = DP[t][a][b][pass][make_pair(ast, bst)].second + bs;
		return res;
	}

	if (t == 0) {
		if (a == N) {
			int s = 0;
			for (int i = b; i < M; i++) {
				if (B[i] != -1)s += B[i];
				else bst = 0;
			}
			return make_pair(as + ast, bs + bst + s);
		}

		pair<int, int>p1, p2;
		if (A[a] != -1) {
			p1 = solve(t ^ 1, a + 1, b, ast + A[a], bst, as, bs, 0);
		}
		else {
			p1 = solve(t ^ 1, a + 1, b, ast, 0, as, bs, 0);
		}

		if (pass == 1) {
			p2 = make_pair(as, bs);
		}
		else if (ast == 0 && bst == 0) {
			p2 = solve(t ^ 1, a, b, 0, 0, as + ast, bs + bst, 1);
		}
		else {
			p2 = solve(t ^ 1, a, b, 0, 0, as + ast, bs + bst, 0);
		}

		if (p1.first - p1.second >= p2.first - p2.second) {
			used[t][a][b][pass][make_pair(ast, bst)] = true;
			DP[t][a][b][pass][make_pair(ast, bst)].first = p1.first - as;
			DP[t][a][b][pass][make_pair(ast, bst)].second = p1.second - bs;

			return p1;
		}
		else {
			used[t][a][b][pass][make_pair(ast, bst)] = true;
			DP[t][a][b][pass][make_pair(ast, bst)].first = p2.first - as;
			DP[t][a][b][pass][make_pair(ast, bst)].second = p2.second - bs;

			return p2;
		}
	}
	else {
		if (b == M) {
			int s = 0;
			for (int i = a; i < N; i++) {
				if (A[i] != -1)s += A[i];
				else ast = 0;
			}
			return make_pair(as + ast + s, bs + bst);
		}

		pair<int, int>p1, p2;
		if (B[b] != -1) {
				p1 = solve(t ^ 1, a, b + 1, ast, bst + B[b], as, bs, 0);
		}
		else {
			p1 = solve(t ^ 1, a, b + 1, 0, bst, as, bs, 0);
		}

		if (pass == 1) {
			p2 = make_pair(as, bs);
		}
		else if (ast == 0 && bst == 0) {
			p2 = solve(t ^ 1, a, b, 0, 0, as + ast, bs + bst, 1);
		}
		else {
			p2 = solve(t ^ 1, a, b, 0, 0, as + ast, bs + bst, 0);
		}

		if (p1.second - p1.first >= p2.second - p2.first) {
			used[t][a][b][pass][make_pair(ast, bst)] = true;
			DP[t][a][b][pass][make_pair(ast, bst)].first = p1.first - as;
			DP[t][a][b][pass][make_pair(ast, bst)].second = p1.second - bs;

			return p1;
		}
		else {
			used[t][a][b][pass][make_pair(ast, bst)] = true;
			DP[t][a][b][pass][make_pair(ast, bst)].first = p2.first - as;
			DP[t][a][b][pass][make_pair(ast, bst)].second = p2.second - bs;

			return p2;
		}
	}
}

int main()
{
	cin >> N >> M;
	A.resize(N), B.resize(M);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	pair<int, int>ans = solve(0, 0, 0, 0, 0, 0, 0, 0);

	cout << ans.first - ans.second << endl;

	return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N;
  cin>>N;
  vector<ll> v(N);
  cinv(v,0,N);
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());

  ll Al=0,Bo=0;
  FOR(i,0,N){
    if(i%2==0) Al+=v[i];
    else Bo+=v[i];
  }
  cout<<Al-Bo<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdexcept>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

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

   string s;
   int n = 0;
   cin >> s;

   rep(i,s.size()){
      n += (int)(s[i] - '0');
   }

   if(stoi(s) % n == 0){
      cout << "Yes" << endl;
   }else{
      cout << "No" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using AR2 = array<int, 2>;
constexpr int MOD{1000000000 + 7};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int dx[4]{1, 0, -1, 0};
constexpr int dy[4]{0, 1, 0, -1};
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; }
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}
// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(0);

    int n, l;
    cin >> n >> l;

    int eat=MOD;
    int apple_pie = 0;

    rep(i,n){
        const int apple = l+i;
        apple_pie += apple;
        if(abs(eat)>abs(apple))
            eat = apple;
    }

    cout << apple_pie - eat << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;

int v[MAX][3];
int n;
int dp[MAX][3];
/*int memo[MAX][3];

int dp(int i, int op) {
	if(i < 0) return 0;
	int f = v[i][op] + dp(i-1, (op+1)%3);
	int s = v[i][op] + dp(i-1, (op+2)%3);
	return max(f,s);
}*/

void solve() {
	memset(v, 0, sizeof v);
	memset(dp, 0, sizeof dp);
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	}
	for(int i=1; i<=n; i++) {
		for(int j=0; j<3; j++) {
			dp[i][j] = v[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);	
		}
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]});
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 27076
#include <iostream>
#include <map>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int c; cin >> c;
	for (int i = 0; i < n; i++) {
		if (s.at(i) != s.at(c - 1)) {
			s.at(i) = '*';
		}
	}

	cout << s << endl;
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())

a = list(map(int, input().split()))

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while r - l > 1:
    mid = (l + r) // 2
    if cal(mid):
        r = mid
    else:
        l = mid
print(r)

Measured memory_bytes: 31092
/*
Author: CNYALI_LK
LANG: C++
PROG: B.cpp
*/
#include<bits/stdc++.h>
#define up(a,b,c) for (int a(b),a##end(c);a<=a##end;++a)
#define down(a,c,b) for (int a(b),a##end(c);a>=a##end;--a)
#define uup(a,c,b) for (int a(b),a##end(c);a<=a##end;++a)
#define udown(a,b,c) for (int a(b),a##end(c);a>=a##end;--a)
#define endl '\n'
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
typedef long long ll;
template<class T>void chkmin(T &a,T b){a=a<b?a:b;}
template<class T>void chkmax(T &a,T b){a=a>b?a:b;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
char a[233333];
ll tot[30];
int main(){
#ifdef cnyali_lk
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	scanf("%s",a);
	up(i,0,strlen(a)-1)++tot[a[i]-'a'];
	ll sum=1;
	up(i,0,25)up(j,i+1,25)sum+=tot[i]*tot[j];
	printf("%lld\n",sum);
	return 0;
}



Measured memory_bytes: 384
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(i)
ab1=copy.copy(ab)
if n==1 and (h-ab[0][1])%ab[0][0]==0:
    print((h-ab[0][1])//ab[0][0]+1)
elif n==1 and (h-ab[0][1])%ab[0][0]!=0:
    print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[1]>=h:
            h-=ak[1]
            ac+=1
        elif ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        if (h-ak[1])%ak[0]==0:
            ac+=((h-ak[1])//ak[0])+1
        else:ac+=((h-ak[1])//ak[0])+2
        print(ac)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 017_agc_b / Link: https://agc017.contest.atcoder.jp/tasks/agc017_b?lang=en  ----- */
/* ------問題------

N 個のマスが一列に並んでいます． 一番左のマスには整数 A が，一番右のマスには整数 B が書かれており，他のマスには何も書かれていません．
青橋君は，何も書かれていないマスに整数を書き込み，次の条件を満たすようにしたいです：
どの隣接する 2 マスについても，書かれている整数の差は C 以上 D 以下である．
青橋君は，この条件を満たす限り，いくらでも大きい整数や小さい整数を書き込むことができます． 青橋君が条件を満たすように整数を書き込むことができるかを判定してください．

-----問題ここまで----- */
/* -----解説等-----

つくれる値は連続しているので、その上限と下限だけを実際に確認してこれがBを含んでいるかを確認すればよい。

----解説ここまで---- */

LL N, A, B, C, D;

LL ans = 0LL;

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

	cin >> N >> A >> B >> C >> D;
	if (A > B)swap(A, B);
	if (C > D)swap(C, D);
	FOR(i, 0, N - 1) {
		{
			LL up = i*D - (N - i - 1)*C + A;
			LL down = i*C - (N - i - 1)*D + A;
			if (down <= B&&B <= up)ans = 1;
		}
		{
			LL up = -(i*D - (N - i - 1)*C) + A;
			LL down = -(i*C - (N - i - 1)*D) + A;
			if (down <= B&&B <= up)ans = 1;
		}
	}

	cout <<(ans?"YES":"NO") << "\n";

	return 0;
}


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

vector<int> u;
vector<int> v;
vector<int> w;

int main()
{
    int L;
    scanf("%d", &L);
    int n = log(L+0.5) / log(2) + 1;
    for (int i = 1; i < n; ++i)
    {
        u.push_back(i);
        v.push_back(i+1);
        w.push_back(1<<(i-1));
        u.push_back(i);
        v.push_back(i+1);
        w.push_back(0);
    }
    int t = 0;
    while (L)
    {
        t ++;
        if (L == 1) break;
        if (L & 1)
        {
            u.push_back(t);
            v.push_back(n);
            w.push_back((L-1) << (t-1));
        }
        L /= 2;
    }
    printf("%d %d\n", n, u.size());
    for (int i = 0; i < u.size(); ++i)
        printf("%d %d %d\n", u[i], v[i], w[i]);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j*i <= n; j++){
            ans += i*j;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
int main() {
    int N;    
    cin>>N;
    string str;
    str=to_string(N);
    int n=str[str.length()-1]- '0';
    //cout<<n<<endl;
    switch(n){
      case 2:
      case 4:
      case 5:
      case 7:
      case 9:
      	cout<<"hon"<<endl;
        break;
      case 0:
      case 1:
      case 6:
      case 8:
      	cout<<"pon"<<endl;
        break;
      case 3:
        cout<<"bon"<<endl;
        break;
    }
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	int a[n];
	REP(i,n) cin >> a[i];
	map<int, int> cnt;
	REP(i,n) cnt[a[i]]++;
	int ans = 0;
	for(auto i : cnt){
		if(i.second < i.first) ans += i.second;
		else ans += i.second - i.first;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
//কী পেয়েছো তুমি, কী চেয়েছিলে তুমি.? হিসেবটা তোমার বড়ই গড়মিল...!!//
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+ 5;
int id[MAX], nodes, edges;
pair <long long, pair<int, int> > p[MAX];

void initialize()
{
    for(int i = 0;i < MAX;++i)
        id[i] = i;
}

int root(int x)
{
    while(id[x] != x)
    {
        id[x] = id[id[x]];
        x = id[x];
    }
    return x;
}

void union1(int x, int y)
{
    int p = root(x);
    int q = root(y);
    id[p] = id[q];
}

long long kruskal(pair<long long, pair<int, int> > p[])
{
    int x, y;
    long long cost, minimumCost = 0;
    for(int i = 0;i < edges;++i)
    {
        // Selecting edges one by one in increasing order from the beginning
        x = p[i].second.first;
        y = p[i].second.second;
        cost = p[i].first;
        // Check if the selected edge is creating a cycle or not
        if(root(x) != root(y))
        {
            minimumCost += cost;
            union1(x, y);
        }
    }
    return minimumCost;
}

int main()
{
    int x, y;
    long long weight, cost, minimumCost;
    initialize();
    cin >> nodes >> edges;
    for(int i = 0;i < edges;++i)
    {
        cin >> x >> y >> weight;
        p[i] = make_pair(weight, make_pair(x, y));
    }
    // Sort the edges in the ascending order
    sort(p, p + edges);
    minimumCost = kruskal(p);
    cout << minimumCost << endl;
    return 0;
}

//GOOD BYE



Measured memory_bytes: 5068