akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;



int main(void) {
  int n,x;
  cin >> n >> x;
  vi a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n-1){
    if(a[i]+a[i+1]>x){
      int p = a[i] + a[i+1] -x;
      a[i+1] = max(0,a[i+1]-p);
      ans += p;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define int long long

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

	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++)
		cin >> vec[i];
	sort(vec.begin(), vec.end());
	if (vec.size() % 2)
		cout << 0 << endl;
	else
		cout << vec[vec.size() / 2] - vec[vec.size() / 2 - 1] << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int N, M;
int cnt[55];

int main(void)
{
	cin >> N >> M;
	
	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		cnt[a]++;
		cnt[b]++;
	}
	
	for(int i = 1; i <= N; i++){
		cout << cnt[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# ABC156b


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n, k = map(int, input().split())
    ans = []
    for i in range(30, -1, -1):
        t = n//k**i
        if len(ans) == 0 and t == 0:
            continue
        ans.append(t)
        n = n-k**i*t
    print(len(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ans = max({a,b,c})*10 + a + b + c - max({a,b,c});
  cout << ans << endl;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (200006)
ll n, x, y, C[MAXN], W[MAXN], f[MAXN], inv[MAXN], mod=1e9+7;
vector<ll> v[MAXN];
struct ufds_ {
	int p[MAXN];
	ufds_ () { FOR(i,0,MAXN-1) p[i]=i; }
	void merge(ll x,ll y){
		p[find(x)]=find(y);
	}
	ll find(ll x) { return (p[x]==x)?x:p[x]=find(p[x]); }
	bool same(ll a,ll b) { return find(a)==find(b); }
} ufds;
int main()
{
	// freopen("int","r",stdin);
	auto qexp=[&](ll x,ll e) {
		ll sum=1;
		while(e){
			if(e&1)sum*=x,sum%=mod;
			x*=x,x%=mod;
			e>>=1;
		}
		return sum;
	};
	f[0]=inv[0]=1; FOR(i,1,MAXN-1) f[i]=f[i-1]*i%mod, inv[i]=qexp(f[i],mod-2);
	FAST
	cin>>n>>x>>y;
	FOR(i,1,n) {
		cin>>C[i]>>W[i];
	}
	vector<ll> mi(n+1, n+1);
	W[n+1]=LLINF;
	FOR(i,1,n) if(W[i] < W[mi[C[i]]]) mi[C[i]]=i;
	FOR(i,1,n) if(mi[C[i]]^i) if(W[mi[C[i]]]+W[i]<=x) W[i]=W[mi[C[i]]], ufds.merge(i,mi[C[i]]);
	ll lowest=0; mi[0]=n+1;
	FOR(i,1,n) if(mi[i]<=n && W[mi[i]] < W[mi[lowest]]) lowest=i;
	FOR(i,1,n) if(mi[i]<=n && W[mi[i]]+W[mi[lowest]]<=y && i!=lowest) ufds.merge(mi[i], mi[lowest]);
	FOR(i,1,n) if(C[i] != lowest && mi[C[i]] != i && W[i]+W[mi[C[i]]]>x && C[ufds.find(mi[C[i]])] != C[i] && W[i]+W[mi[lowest]] <= y) assert(ufds.find(mi[C[i]])==mi[lowest]), ufds.merge(i, mi[C[i]]); 
	ll val=LLINF; FOR(i,1,n) if(i!=lowest && mi[i]<=n && ufds.same(mi[i], mi[lowest])) val=min(val, W[mi[i]]);
	FOR(i,1,n) if(C[i] == lowest && !ufds.same(i, mi[lowest]) && val+W[i]<=y) ufds.merge(i, mi[lowest]); 
	FOR(i,1,n) {
		v[ufds.find(i)].pb(C[i]);
	}
	ll ans = 1;
	FOR(i,1,n) if(ufds.find(i)==i) {
		ans *= f[v[i].size()], ans%=mod;
		sort(all(v[i]));
		ll co = 0;
		FOR(j,0,siz(v[i])-1) {
			if(j==0||v[i][j-1]==v[i][j]) ++ co;
			else {
				ans *= inv[co], ans%=mod;
				co=1;
			}
		}
		ans *= inv[co], ans%=mod;
	}
	cout<<ans<<'\n';
}
/*
9 3 4
3 2
1 3
1 3
4 3
3 2
2 2
2 1
2 2
2 3
*/


Measured memory_bytes: 19456
use std::collections::HashMap;
use std::f64;

#[allow(unused)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
#[allow(unused)]
fn round_to_integer(a: f64, digit: u8) -> i64 {
    let mut ai: i64;
    let mut d = digit;
    let mut p = 1;

    while d > 0 {
        p *= 10;
        d -= 1;
    }
    ai = (a * p as f64) as i64;

    while ai as f64 / p as f64 - a > 0.5 / p as f64 {
        ai -= 1;
    }
    while ai as f64 / p as f64 - a < -0.5 / p as f64 {
        ai += 1;
    }
    ai
}
fn trial_division(mut n: usize) -> HashMap<usize, usize> {
    let mut primes = HashMap::new();
    let mut i = 2;

    //  n を root n 以下の整数で割り切れるまで割っていく
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            if primes.contains_key(&i) {
                let x = primes.get_mut(&i).unwrap();
                *x += 1;
            } else {
                primes.insert(i, 1);
            }
        }
        i += 1;
    }

    // 最後にnが素数になっている場合はそれ自身も素因数に含めて終了
    if n > 1 {
        if primes.contains_key(&n) {
            let x = primes.get_mut(&n).unwrap();
            *x += 1;
        } else {
            primes.insert(n, 1);
        }
    }
    primes
}

fn main() {
    input! {
        h1 : u16,
        m1 : u16,
        h2 : u16,
        m2 : u16,
        k : u64,
    }
    let t1 = (h1 * 60) + m1;
    let t2 = (h2 * 60) + m2;
    let diff = (t2 - t1) as u64;

    let ans = diff - k;
    println!("{}", ans);
}


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

int main()
{
  vector<int> x(5);
  int ans = -1;
  for (int i = 0; i < x.size(); i++)
  {
    cin >> x.at(i);
    if (x.at(i) == 0)
    {
      ans = i + 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
N,A,B = map(int,input().split())
if A > B :
    ans = 0
elif N == 1 :
    if A != B :
        ans = 0
    else :
        ans = 1
elif N == 2 :
    ans = 1
else :
    ans = (B-A)*(N-2)+1
print(ans)


Measured memory_bytes: 2940
n = int(input())
s = input()
moji = [chr(i)for i in range(97,97+26)]
ans = 0
for i in range(n):
    count = 0
    for key in moji:
        if key in s[i:] and key in s[:i]:
            count +=1
    if count > ans:
        ans = count
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String... args) {
    Scanner input = new Scanner(System.in);
    
    int n = input.nextInt();
    int m = input.nextInt();
    
    PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());
    
    for (int i = 0; i < n; i++) {
      queue.offer(input.nextInt());
    }
    
    while (m-- != 0 && !queue.isEmpty()) {
    	int max = queue.poll();
      	if (max / 2 != 0) {
          queue.offer(max / 2);
        }
    }
    
    long ans = 0;
    while (!queue.isEmpty()) {
      ans += queue.poll();
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 58856
n, k = map(int, input().split())

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

#n = 2 * 10 ** 5
#a = [0] * n
cnt = 0

while cnt < k:
    imos = [0] * (n + 1)
    for i in range(n):
        imos[max(i - a[i], 0)] += 1
        imos[min(i + a[i] + 1, n)] -= 1
    for i in range(n):
        imos[i + 1] += imos[i]
    a = imos[0:n]
    cnt += 1
    if min(a) == n:
        break
print(*a)


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

int main() {
   int a,b,k;
   cin >> a >> b >> k;
   int ans=max(a,b)+1,cnt=0;
   while(cnt!=k&&ans!=1){
      ans--;
      if(a%ans==0&&b%ans==0)
      cnt++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.*;
import java.text.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int h=0;
		int count=0;

		for(int i = 1; i<=n; i++){
			h = sc.nextInt();
			if(h >= k){
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 48116
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define ull unsigned long long
#define si short int
#define ll long long
#define piii pair<pair<int, int>, int>
#define piiii pair<pair<int, int>, pair<int, int>>

/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

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

inline int pwm(ll xx, ll pow, int MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return (int) mlt;
}

inline ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll xx, yy;
    ll gc = gcdex(b, a % b, yy, xx);
    x = xx;
    y = yy - (a / b) * xx;
    return gc;
}

inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }

inline int64_t hilbertOrder(int x, int y, int pow, int rotate) {
    if (pow == 0) {
        return 0;
    }
    int hpow = 1 << (pow-1);
    int seg = (x < hpow) ? (
            (y < hpow) ? 0 : 3
    ) : (
                      (y < hpow) ? 1 : 2
              );
    seg = (seg + rotate) & 3;
    const int rotateDelta[4] = {3, 0, 0, 1};
    int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
    int nrot = (rotate + rotateDelta[seg]) & 3;
    int64_t subSquareSize = int64_t(1) << (2*pow - 2);
    int64_t ans = seg * subSquareSize;
    int64_t add = hilbertOrder(nx, ny, pow-1, nrot);
    ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
    return ans;
}
/*-----------------------------------------------------MATH------------------------------------------------*/

void solve() {
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    if(h>w) swap(h,w);
    cout<<(n+w-1)/w;
}

int main() {
    /*ios::sync_with_stdio(false);
    cin.tie(nullptr);*/
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);
    unsigned int beg_time = clock();

    int n = 1;
    for (int i = 0; i < n; i++) solve();


    unsigned int end_time = clock();
    //cout<<endl<<endl<<end_time-beg_time;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int n, m, x;
int c[12];
int a[12][12];
int ans = INF;

void dfs(vector<bool> b) {
    if ((int)b.size() == n) {
        int cost = 0;
        int p[m] = {};
        rep(i, 0, b.size()) {
            if (b[i] == true) {
                cost += c[i];
                rep(j, 0, m) {
                    p[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        rep(i, 0, m) {
            if (p[i] < x) {
                ok = false;
            }
        }
        if (ok) ans = min(ans, cost);
        return;
    }
    b.push_back(false);
    dfs(b);
    b.pop_back();
    b.push_back(true);
    dfs(b);
    b.pop_back();
}

int main() {
    cin >> n >> m >> x;
    rep(i, 0, n) {
        cin >> c[i];
        rep(j, 0, m) cin >> a[i][j];
    }
    vector<bool> b;
    dfs(b);
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


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

int main()
{
    char a[10], b[10];

    scanf("%s%s", a, b);
    if (a[0] == 'D') {
        if (b[0] == 'D') {
            b[0] = 'H';
        } else {
            b[0] = 'D';
        }
    }
    puts(b);
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s;
    cin >> s;
    switch (s) {
      case 'A': cout << "T\n";
                break;
      case 'T': cout << "A\n";
                break;
      case 'C': cout << "G\n";
                break;
      case 'G': cout << "C\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main ()
{
  int s = 0, w = 0;
  cin >> s >> w;
  if(w >= s)
  {
    cout <<"unsafe" << endl;
  }
  else
  {
  	cout << "safe" << endl; 
  }
  return 0; 
}



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

int main() {
  int D; cin >> D;
  if (D == 25) cout << "Christmas" << endl;
  else if (D == 24) cout << "Christmas Eve" << endl;
  else if (D == 23) cout << "Christmas Eve Eve" << endl;
  else if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int N, A, B, plan1, plan2, min;
	cin >> N >> A >> B;
	plan1 = N*A;
	plan2 = B;
	if (plan1 > plan2) {
		min = plan2;
	}
	else {
		min = plan1;
	}
	cout << min << endl;
}

Measured memory_bytes: 256
import fractions
import math 
def trial_division(n):
    #素因数を格納するリスト
    factor = [1]
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return [1, n]
    else:
        factor.append(n)
        return factor

A, B = map(int, input().split())
gcd = fractions.gcd(A, B)
N = len(set(trial_division(gcd)))
print(N)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int n,a[200001],k;
long long ans;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    sort(a+1,a+n+1);
    for(int i=1;i<=n-k;i++){
        ans+=a[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
#AGC008A
import sys
#sys.setrecursionlimit(100000)

tmp = input().split()
x,y = list(map(lambda a: int(a), tmp))

ans=0
if(abs(y)>abs(x)):
	ans+=abs(y)-abs(x)
	if(x<0):
		ans+=1
	if(y<0):
		ans+=1
else:
	ans+=abs(x)-abs(y)
	if(x>0):
		ans+=1
	if(y>0):
		ans+=1
print(ans)



Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace CompetitionPrograming2
{
    public sealed class Program
    {
        public static void Main(string[] _) { Solve(); }
        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var machines = new List<Tuple<long, long>>();
            for (int i = 0; i < n; i++)
            {
                var xl = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
                var x = xl[0];
                var l = xl[1];
                machines.Add(Tuple.Create(x - l, x + l));
            }

            var count = n;
            var rightLimit = long.MinValue;
            foreach (var t in machines.OrderBy(m => m.Item2))
            {
                if (t.Item1 < rightLimit)
                {
                    count--;
                }
                else
                {
                    rightLimit = Math.Max(t.Item2, rightLimit);
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 24368
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
using namespace std;
typedef long long ll;

#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 out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,dist[100000]={},u,v,w;
bool visited[100000]={};
vector<pair<int, int> > G[100000];

void solve(int now,int dis){
    visited[now]=1;
    dist[now]=dis;
    for(auto next : G[now]){
        if(!visited[next.first])solve(next.first,next.second+dis);
    }

}

int main(){
    cin>>N;
    rep(i,N-1){
        cin>>u>>v>>w;
        u--;
        v--;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    solve(0,0);
    rep(i,N){
        if(dist[i]%2){
            out(1);
        }
        else{
            out(0);
        }
    }
}


Measured memory_bytes: 7680
#include<stdio.h>

int binarySearch(int, int *, int);

int main(){

  int i, n, q, key, cnt=0;

  scanf("%d", &n);

  int S[n];

  for(i=0;i<n;i++) scanf("%*c%d", &S[i]);

  scanf("%d", &q);

  int T[q];

  for(i=0;i<q;i++) scanf("%*c%d", &T[i]);

  for(i=0;i<q;i++){

    key=binarySearch(n, S, T[i]);

    if(key) cnt++;

  }

  printf("%d\n", cnt);

  return 0;

}

int binarySearch(int n, int *A, int key){

  int mid, left=0, right=n;

  while(left<right){

    mid=(left+right)/2;

    if(key==A[mid]) return 1;

    else if(key>A[mid]) left=mid+1;

    else right=mid;

  }

  return 0;

}



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

class Process{
  public:
  string name;
  int time;
};

class myqueue{
  public:
  int size;
  int begin;
  int end;
  Process v[111111];
  myqueue(){
    size = 111111;
    begin = 0;
    end = 0;      //[begin, end)
  }

  void push(Process a){
    v[end] = a;
    end = (end + 1) % size;
  }
  Process front(){
    return v[begin];
  }
  void pop(){
    begin = (begin + 1) % size;
  }
  bool isEmpty(){
    return begin == end;
  }
  void pr(){
    for(int i = begin; i < end; i++){
      cout << v[i].name << " ";
    }
    cout << endl;
  }
};

int main(void){
  int n, q;
  myqueue que;
  cin >> n >> q;
  for(int i = 0; i < n; i++){
    Process tmp;
    cin >> tmp.name >> tmp.time;
    que.push(tmp);
  }
  int t = 0;
  while(!que.isEmpty()){
    Process a = que.front(); que.pop();
    if(a.time > q){
      a.time -= q;
      que.push(a);
      t += q;
    }else{
      t += a.time;
      cout << a.name << " " << t << endl;
    }
  }
  return 0;
}

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

int main(void)
{
	char s[101] = {0};
	char n[256] = {0};
	char r[256] = {0};
	int len = 0;
	int sum = 0;

	scanf("%s", s);

	len = strlen(s);

	if (3 <= len && len <= 100) {
		int len_tmp = 0;
		sum = len - 2;
		sprintf(n, "%d", sum);
		r[0] = s[0];
		strncpy(&r[1], &n[0], strlen(n));
		len_tmp = strlen(r);
		r[len_tmp] = s[len - 1];
	}

	printf("%s\n", r);

	return 0;
}

Measured memory_bytes: 128
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/
#include<bits/stdc++.h>
#define mod 1000000007
#define modc 998244353
#define pb push_back
#define ll long long
#define ull unsigned long long
using namespace std;
void solve()
{
	int i,j;
	int n,m;
	ll sum = 0;
	cin >> n >> m;
	vector<int>a(n);
	for(i=0;i<n;i++)
	{
		cin >> a[i];
		sum+=a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
	if(a[m-1] >= sum*1.0/(4*m))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
		solve();

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    while(1)
    {
        long long n;
        cin>>n;if(!n)return 0;
        char t[100000][2];
        for(int i=0;i<n;++i){
            char a,b;
            cin>>a>>b;
            t[i][0]=a;
            t[i][1]=b;
        }
        long long m;
        cin>>m;
        for(int i=0;i<m;++i){
            char a;
            cin>>a;
            bool flag=true;
            for(int j=0;j<n;++j){
                if(t[j][0]==a){
                    cout<<t[j][1];
                    flag=false;
                }
            }
            if(flag)cout<<a;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1160
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<endl;

    

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    while (true) {
        ll n;
        cin >> n;
        if (n == 0) return;
        vector<ll> range(86405, 0);
        rep(i, n) {
            string s, t;
            cin >> s >> t;
            ll s1 = 0, s2 = 0;
            s1 = stoll(s.substr(0, 2)) * 3600 + stoll(s.substr(3, 2)) * 60 +
                 stoll(s.substr(6, 2));
            s2 = stoll(t.substr(0, 2)) * 3600 + stoll(t.substr(3, 2)) * 60 +
                 stoll(t.substr(6, 2));
            range[s2]--;
            range[s1]++;
        }
        rep(i, 86403) {
            range[i + 1] += range[i];
        }
        cout << *max_element(range.begin(), range.end()) << '\n';
    }
}

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



Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,b) for(i=0;i<b;i++)
#define rep1(i,b) for(i=1;i<=b;i++)
#define pdn(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define sd(n) scanf("%d",&n)
#define pn printf("\n")
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, LL n)
{LL ret=1;LL b=a;while(n) {if(n&1)
    ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (LL)ret;}
#define MAXK 100000
#define MAXN 1000000000
int ar[MAXK];
int get(int n, int k){
    int i=0;
    while(i<k and ar[i]<=n)i++;
    return n-i;
}
typedef unsigned long long int ULL;
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

bool isSafe(int r, int c, vector<vector<int> > arr) {
	int n = arr.size();
	int m = arr[0].size();
	return (r>=0 && r<n && c>=0 && c<m);
}

/////////////////////////////////////////////////////////////
bool diffSign(int a,int b) {
	return ((a>0 && b<0) || (a<0 && b>0));
}  

int main() 
{ 
	int n,a;
	cin>>n;
	cin>>a;
	cout<<((n*n)-a)<<endl;
	return 0; 
} 


Measured memory_bytes: 256
require 'prime'

N, P = gets.chomp.split.map(&:to_i)
prime_div = P.prime_division

if prime_div.count == 0
  puts 1
else
  ans = 1
  prime_div.each do |a|
    n = a[1] / N
    if n >= 1
      n.times do
        ans *= a[0]
      end
    end
  end
  puts ans
end


Measured memory_bytes: 2300
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	int sumapapo = 0;
	int sumapopa= 0;
	int mayor = 0;
	int indice = 0;
	vector<int>number;
	cin >> n;
	int auxpri, aux;
	for (int i = 0; i < n; i++) {
		cin >> auxpri;
		number.push_back(auxpri);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0;j< number.size(); j++) {
			if (number[j] > mayor) {
				aux = number[j];
				mayor = aux;
				indice = j;
			}
		}
		number.erase(number.begin() + indice);
		if (i % 2 == 0)
			sumapopa+= mayor;
		else sumapapo+=mayor;	
		mayor = 0;
}
	int dif;
	dif = sumapapo - sumapopa;
	if (dif < 0)
		dif *= -1;

	cout << dif;
	return(0);
}

Measured memory_bytes: 256
import sys

n,k = map(int,input().split())
elements = [list(map(int,input().split())) for _ in range(n)]

elements.sort(key=lambda x: x[0])

count = 0

for elem in elements:
    count += elem[1]
    if count >= k:
        print(elem[0])
        sys.exit()

Measured memory_bytes: 29144
#include<bits/stdc++.h>
using namespace std;
char dat[100001];
bool z[100001]; 
int main()
{
	int n;
	cin>>n;
	cin>>dat;
	dat[0];
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			z[0]=i;
			z[1]=j;
			for(int k=1;k<n-1;k++)
			{
				z[k+1]=z[k-1]^z[k]^(dat[k]=='x');
			}
			if((dat[n-1]=='x')==(z[n-2]^z[n-1]^z[0])&&(dat[0]=='x')==(z[n-1]^z[0]^z[1]))
			{
				for(int k=0;k<n;k++)
				{
					cout<<(z[k]?'W':'S');
				}
				cout<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<endl;
	return 0;
}

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

int main() {
	// your code goes here
	int n;cin>>n;
	int a[n];
	int net=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		net^=a[i];
	}
	for(int i=0;i<n;i++){
		int b=net^a[i];
		cout<<b<<" ";
	}cout<<endl;
	
	
	return 0;
}

Measured memory_bytes: 4364
import java.io.BufferedInputStream;
import java.util.Arrays;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a=sc.nextInt();
        int m[]=new int[a];
        int min=a;
        int count=0;
        for(int i=0;i<a;i++) {
            m[i] = sc.nextInt();
            if(m[i]<min)
                min=m[i];
            if(m[i]<=min)
                count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 85008
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  ll X;
  cin>>X;

  ll ans=1000*(X/500);
  X%=500;
  ans+=5*(X/5);
  cout<<ans<<endl;

  return 0;
}


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

vector<vector<int>> mat(51,vector<int>(51,0));
vector<bool> visited(51,false);
int n, m;

void dfs(int now){
    visited[now] = true;
    rep(i,n){
        if(mat[now][i] && !visited[i]) dfs(i);
    }
}

int main(){
    cin >> n >> m;
    vector<int> a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        mat[a[i]][b[i]] = 1; mat[b[i]][a[i]] = 1;
    }
    int ans = 0;
    rep(i,m){
        mat[a[i]][b[i]] = mat[b[i]][a[i]] = 0;
        rep(j,n) visited[j] = false;
        dfs(0);
        bool flag = false;
        rep(j,n) if(!visited[j]) flag = true;
        if(flag) ans++;
        mat[a[i]][b[i]] = mat[b[i]][a[i]] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N, M;
    int A[50][50];
    int bucket[50];
    cin >> N >> M;
    for (int i = 0; i < N; i++){
        int K;
        cin >> K;
        for (int j = 0; j < K; j++){
            cin >> A[i][j];
            bucket[A[i][j]]++;
        }
    }
    int count = 0;
    for (int i = 1; i <= M; i++){
        if (bucket[i] == N) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    int n,k;cin >> n >> k;
    vector<LL> a(n);
    LL mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    LL l = 0, r = mx;
    while(r - l > 1){
        LL m = (r + l) / 2;
        LL cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += (a[i] + m - 1) / m - 1;
        }
        if(cnt > k) l = m;
        else r = m;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 4764
n, q = gets.split.map(&:to_i)

processes = n.times.map{|e|
  name, time = gets.split
  [name, time.to_i]
}

processed = []

t = 0
until processes.empty?
  top = processes.shift

  name, time = top
  rest = time - q

  if rest > 0
    processes << [name, rest]
    t += q
  else
    processed << [name, t + time]
    t += time
  end
end

processed.each do |name, t|
  puts "#{name} #{t}"
end



Measured memory_bytes: 16832
s = input().strip()
n = len(s)
cnt = 0

odd, even = 1, 0
flag = 0  # 0 for odd and 1 for even

for i in range(1, n):
    if s[i] == s[i-1]:
        flag = 1 - flag

    if flag == 0:
         odd += 1
    else:
        even += 1

print(min(odd, even))

Measured memory_bytes: 3188
N = int(input())
a = list(map(int, input().split()))
q = int(input())
s = sum(a)
dic = {}
for i in range(N):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
for _ in range(q):
    b, c = map(int, input().split())
    if b in dic:
        s = s + (c-b)*dic[b]
        print(s)
        if c in dic:
            dic[c] += dic[b]
        else:
            dic[c] = dic[b]
        del dic[b]
    else:
        print(s)

Measured memory_bytes: 20668
#include <bits/stdc++.h>
using namespace std;
int comp(const pair<int,int>&a, const pair<int,int>&b)
{
  return (a.first<b.first);
}
int main()
{
  int n,m;
  cin>>n>>m;
  vector<pair<int,int> >a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i].first>>a[i].second;
  }
  sort(a.begin(),a.end(),comp);
  long long ans=0;
  int count=0;
  for(int i=0;i<n;i++)
  {
    if((m-count)>a[i].second)
    {
      ans+=((long long )a[i].first*a[i].second);
      count+=a[i].second;
    }
    else
    {
      ans+=((long long)a[i].first*(m-count));
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}
    

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
  int h, w;

  while(true)
  {
    cin	>> h >> w;
    if(!h && !w)
      break;
    for(int i = 0; i < h; i++)
    {
      for(int j = 0; j < w; j++)
        cout << "#";
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long S, long long W)
{
  cout << (W >= S ? "unsafe" : "safe") << endl;
}

signed main()
{
  long long S;
  scanf("%lld", &S);
  long long W;
  scanf("%lld", &W);
  solve(S, W);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int X;cin>>X;
    int m=100;
    int ans=0;
    while(m<X){
        int z=m*1.01;
        m=z;
        ans++;
    }
    cout<<ans<<endl;
}


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

const int limit = 50;

int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visted[limit];

void dfs(int v) {
    visted[v] = true;
    for(int v2 = 0; v2 < n; ++v2) {
        // vと接続されていないノードをskip
        if (graph[v][v2] == false) continue;
        // 探索済みのノードは２回探さないようにする
        if (visted[v2] == true) continue;
        // vから接続されている次のノードを探す
        dfs(v2);
    }
    // 全部抜けたとき，0からつながっているノードに関してはvistedにtrueが入る
    // 連結であるなら，全部にtrueが入っているべき
}


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

    for (int i =0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;

        // a->b, b->a are connected
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;

    for (int i = 0; i < m; ++i) {
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        for(int j = 0; j < n; ++j) visted[j] = false;

        dfs(0);

        bool bridge = false;
        for(int z = 0; z < n; ++z) {
            if (visted[z] == false) {
                bridge = true;
                break;
            }
        }

        if (bridge) {
            ans += 1;
        }

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;
 
using ll = long long;
 
//constant
const double EPS = 1e-10;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()
 
//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
 
// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }
 
// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
 
// DP
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; }
 
 
 
 
// ***************************************
 
 
int main() {
 
    int K;
    cin >> K;
    ll ans = 0;
    REP(i, K) {
        REP(j, K) {
            int tmp = gcd(i + 1, j + 1);
            REP(k, K) {
                ans += (gcd(tmp, k + 1));
            }
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3588
s=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
h=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
c=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
d=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
n=gets.to_i
n.times do
  a,b=gets.split
  b=b.to_i
  s[b]=0 if a=='S'
  h[b]=0 if a=='H'
  c[b]=0 if a=='C'
  d[b]=0 if a=='D'
end
for i in 1..13
  puts 'S '+i.to_s if s[i]>0
end
for i in 1..13
  puts 'H '+i.to_s if h[i]>0
end
for i in 1..13
  puts 'C '+i.to_s if c[i]>0
end
for i in 1..13
  puts 'D '+i.to_s if d[i]>0
end


Measured memory_bytes: 6884
import sys
input = sys.stdin.readline

n = int(input())
candidate = []
ans = 0

import itertools

for i in range(1, n+1):
    if (i % 10) != 0:
        candidate.append(str(i))
for i, j in (itertools.product(['1', '2', '3', '4', '5', '6', '7', '8', '9'], repeat=2)):
# for i, j in (itertools.product(range(1, 10), repeat=2)):
    i_j = 0
    j_i = 0
    for k in candidate:
        start, end = k[0], k[-1]
        # start, end = int(k[0]), int(k[-1])
        if start == i and end == j:
            i_j += 1
        if start == j and end == i:
            j_i += 1
    ans += (i_j * j_i)

print(ans)


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

int main(){

  string S, T;
  cin >> S >> T;

  bool flag = 0;

  for(int i = 0; i < S.size(); i++){
    if(S[i] != T[i]) flag = 1;
  }

  if(flag) cout << "No" << endl;
  else cout << "Yes" << endl;


  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <limits>
#include <cmath>
#include <typeinfo>


using namespace std;

int main() {
	int a = 0, b = 0;
	cin >> a >> b;
	if(a >= 13) {
		cout << b << endl;
	}
	else if(a >= 6 && a <= 12) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

    return 0;
}

Measured memory_bytes: 256
/* AtCoder My Practice
 * author: Leonardone @ NEETSDKASU
 */
import java.util.Scanner;
 
public class Main
{
    static class Range
    {
        int lower, upper;
        Range lbound = null, ubound = null;
        Range(int l, int u) { lower = l; upper = u; }
    }
    
    static Range range;
    static long sum = 0L;
    
    static void calc(int value, int index)
    {
        Range tmp = range;
        long len;
        for (;;)
        {
            if (tmp.lower <= index && index <= tmp.upper)
            {
                len = (long)(tmp.upper - tmp.lower + 1);
                sum += (len * (len + 1L) / 2L) * (long)value;
                len = (long)(tmp.upper - index);
                sum -= (len * (len + 1L) / 2L) * (long)value;
                len = (long)(index - tmp.lower);
                sum -= (len * (len + 1L) / 2L) * (long)value;
                if (tmp.lower == index)
                {
                    tmp.lower++;
                }
                else if (tmp.upper == index)
                {
                    tmp.upper--;
                }
                else
                {
                    tmp.lbound = new Range(tmp.lower, index - 1);
                    tmp.ubound = new Range(index + 1, tmp.upper);
                    tmp.lower = tmp.upper = index;
                }
                break;
            }
            else if (index < tmp.lower)
            {
                tmp = tmp.lbound;
            }
            else
            {
                tmp = tmp.ubound;
            }
        }
    }
    
    public static void main(String[] args) throws Exception
    {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        
        int[] idx = new int[n + 1];
        
        for (int i = 0; i < n; i++)
        {
            int a = in.nextInt();
            idx[a] = i;
        }
        
        range = new Range(0, n - 1);
        
        for (int i = 1; i <= n; i++)
        {
            calc(i, idx[i]);
        }
        
        System.out.println(sum);
    }
    
    
}

Measured memory_bytes: 48644
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

ll n[2], x, pre, delta, s[2];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n[0] >> n[1];
  FOR(i, 0, 2){
    cin >> pre;
    delta = 0;
    FOR(j, 1, n[i]){
      cin >> x;
      delta += (x - pre) * j;
      delta %= mod;
      s[i] += delta;
      s[i] %= mod;
      pre = x;
    }
  }
  cout << s[0] * s[1] % mod << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;

  vector< pair <long long, int> > fs;
  for(long long i=2;i*i<=n;++i){
    int x=0;
    while(n%i==0){
      n/=i;
      ++x;
    }
    if(x!=0) fs.push_back(make_pair(i,x));
  }
  if (n!=1) fs.push_back(make_pair(n,1));

  int ans=0;
  for(auto p:fs){
    int x=p.second;
    int b=1;
    while(x-b>=0){
      x-=b;
      b+=1;
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val N = readLine()!!.toInt(); val S = readLine()!!

    val W = S.split("#").filter { it.isNotBlank() }.map { it.length }.let { if (S.first() == '.') it.drop(1) else it }
    val B = S.split(".").filter { it.isNotBlank() }.map { it.length }

    val sw = mutableListOf<Int>()
    sw.add(W.sum())
    W.forEach { sw.add(sw.last() - it) }

    val sb = mutableListOf<Int>()
    sb.add(0)
    B.forEach { sb.add(sb.last() + it) }

    val counts = mutableListOf<Int>()
    counts.add(sb.last())
    for (i in B.indices) {
        val w = if (i in sw.indices) sw[i] else 0
        val b = if (i in sb.indices) sb[i] else 0
        counts.add(w + b)
    }
    println(counts.min())
}

Measured memory_bytes: 67844
import sys
def input() : return sys.stdin.readline().strip()

def main():
    ans = 0
    N = int(input())
    test = []
    for _ in range(N):
        A = int(input())
        temp = [tuple(map(int, input().split())) for _ in range(A)]
        test.append(temp) 
    
    # bit full search
    print()
    for bit in range(1<<N):
        isOK = True
        for i in range(N):
            if bit & (1<<i):
                for j, flag in test[i]:
                    j -= 1
                    if flag ^ ((bit>>j) & 1):
                        isOK = False
                        break
        if isOK:
            ans = max(ans, bin(bit).count("1"))
    
    print(ans)

            
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>

int func(int n){
    if(n%2 == 0) return n/2;
    else return 3*n + 1;
}

int main(){
    int s, array[100000] = {};
    scanf("%d", &s);
    array[0] = s; 
    for(int i = 1; i < 100000; i++){
        array[i] = func(array[i-1]);
    }

    for(int i = 1; i < 100000; i++){
        for(int j = 0; j < i; j++){
            if(array[j] == array[i]){
                printf("%d", i+1);
                goto OUT;
            }
        }
    }
    OUT:
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[200001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	if(a[0]+2<=a[n-1]){
		printf("No\n");
		return 0;
	}
	if(a[0]==a[n-1]){
		printf("%s\n",(a[n-1]*2<=n || a[n-1]==(n-1))?"Yes":"No");
		return 0;
	}
	int vu=0;
	for(int i=0;i<n-1;i++){
		if(a[i]!=a[i+1])vu=i+1;
	}
	if(vu>a[0]){
		puts("No");
		return 0;
	}
	int re=a[0]-vu;
	int pt=n-vu-2;
	while(re>0){
		re--;
		pt-=2;
	}
	printf("%s\n",pt>=0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 640