akhauriyash/Code-Regression huggingface dataset:
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int R;
	std::cin >> R;
	
	std::cout << (R * 3.141592 * 2) << "\n";
}


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

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    ll k;
    cin>>k;
    ll p,q;
    p=k/50;q=k%50;
    ll a[50];
    ll tmp=50+p;
    if(q){
        rep(i,50-q,50){
            a[i]=tmp;
            --tmp;
        }
        --tmp;
        rep(i,50-q){
            a[i]=tmp;
            --tmp;
        }
    }
    else{
        --tmp;
        rep(i,50){
            a[i]=tmp;
            --tmp;
        }
    }
    cout<<50<<endl;
    rep(i,50){
        if(i)cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
def main():
    from builtins import int, map, list, float, print, min
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, K = input_number_list()
    h = [input_number() for _ in range(N)]
    h.sort()
    ans = float('inf')
    for i in range(N - K + 1):
        ans = min(ans, h[i + K - 1] - h[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7508
class HashTable:
    def __init__(self, size = 1000003):
        self.size = size
        self.hash_table = [None] * size

    def _gen_key(self, val):
        raw_hash_val = hash(val)
        h1 = raw_hash_val % self.size
        h2 = 1 + (raw_hash_val % (self.size - 1))
        for i in range(self.size):
            candidate_key = (h1 + i * h2) % self.size
            if not self.hash_table[candidate_key] or self.hash_table[candidate_key] == val:
                return candidate_key

    def insert(self, val):
        key = self._gen_key(val)
        self.hash_table[key] = val

    def search(self, val):
        key = self._gen_key(val)
        if self.hash_table[key]:
            return True
        else:
            return False


import sys

n = int(sys.stdin.readline())

simple_dict = HashTable()

ans = ''

for i in range(n):
    operation = sys.stdin.readline()
    if operation[0] == 'i':
        simple_dict.insert(operation[7:])
    else:
        if simple_dict.search(operation[5:]):
            ans += 'yes'
        else:
            ans += 'no'
        ans += '\n'

print(ans, end = '')

Measured memory_bytes: 35908
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
pub fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

fn main() {
    input! {
        a: u64,
        b: u64,
        c: u64,
        d: u64,
    }
    let f = |n: u64, l: u64| -> u64 {
        n + (n/l) - (n/c) - (n/d)
    };
    let l = lcm(c,d);
    println!("{}", f(b,l) - f(a-1,l));
}


Measured memory_bytes: 4352
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a,b;cin>>a>>b;
    cout<<a*b<<endl;


	return;
}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;

    bool ret = false;
    if (v != w) {
        ret = abs(b - a) <= t * (v - w);
    } 

    if (ret) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3640
import sys
s=int(input())
dp=[0]*1000001
dp[s]=1
cnt=1
for i in range(1000001):
  if s%2==1:
    s=3*s+1
  else:
    s//=2
  cnt+=1
  if dp[s]==1:
    print(cnt)
    sys.exit()
  else:
    dp[s]=1

Measured memory_bytes: 69424
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int x,t; cin >> x >> t;
  cout << max(x-t,0);

  return 0;
}


Measured memory_bytes: 256
class BinaryTree
  class Node
    attr_accessor :key, :left, :right, :parent

    def initialize(key)
      @key = key
      @left = nil
      @right = nil
      @parent = nil
    end

    def add_left(node)
      @left = node
      node.parent = self
    end

    def add_right(node)
      @right = node
      node.parent = self
    end
  end

  attr_accessor :count

  def initialize
    @count = 0
    @root = nil
  end

  def insert(z)
    y = nil
    x = @root
    while x != nil do
      y = x
      if z.key < x.key then
        x = x.left
      else
        x = x.right
      end
    end
    
    if y == nil then
      @root = z
    elsif z.key < y.key
      y.add_left(z)
    else
      y.add_right(z)
    end
  end

  def print
    print_inorder
    print_preorder
  end

  def print_inorder
    node = @root
    array = []
    do_print_inorder(node, array) unless node == nil
    puts " #{array.join(' ')}"
  end

  def do_print_inorder(node, array)
    do_print_inorder(node.left, array) if node.left != nil
    array << node.key
    do_print_inorder(node.right, array) if node.right != nil
  end

  def print_preorder
    node = @root
    array = []
    do_print_preorder(node, array) unless node == nil
    puts " #{array.join(' ')}"
  end

  def do_print_preorder(node, array)
    array << node.key
    do_print_preorder(node.left, array) if node.left != nil
    do_print_preorder(node.right, array) if node.right != nil
  end
end


# main
tree = BinaryTree.new
n = gets.chomp.to_i
(n).times do
  command, key = gets.chomp.split
  if command == "insert" then
    tree.insert(BinaryTree::Node.new(key.to_i))
  elsif command == "print" then
    tree.print
  end
end

Measured memory_bytes: 88248
import math
def resolve():
    a = list(int(input()) for _ in range(5))
    mint = 1000
    ans = 0
    for i in range(5):
        ans += math.ceil(a[i]/10)*10
        if a[i]%10 == 0: continue
        mint = min(mint,a[i]%10)
    if mint == 1000:
        print(ans)
    else:
        print(ans+mint-10)
resolve()

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    int edge[n][4];
    rep (i, n) rep (j, 4) cin >> edge[i][j];
    bool used[n];
    fill(used, used + n, false);
    long long res = 1;
    rep (i, n) if (!used[i]) {
      int mx = edge[i][1];
      int cnt = 1;
      int pp = i;
      used[i] = true;
      for (int p = edge[i][0]; p != i; ) {
	used[p] = true;
	if (edge[p][0] == pp) {
	  if (mx == edge[p][3]) {
	    ++cnt;
	  } else if (mx < edge[p][3]) {
	    cnt = 1;
	    mx = edge[p][3];
	  }
	  pp = p;
	  p = edge[p][2];
	} else {
	  if (mx == edge[p][1]) {
	    ++cnt;
	  } else if (mx < edge[p][1]) {
	    cnt = 1;
	    mx = edge[p][1];
	  }
	  pp = p;
	  p = edge[p][0];
	}
      }
      res *= cnt;
      res %= 10007;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}

int a[1000005];
int cnt[1000005];
int gcd(int x, int y){
    while(y){
        x %= y;
        swap(x, y);
    }
    return x;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i = 2; i <= 1000000; i++){
        int k = 0;
        for(int j = i; j <= 1000000; j+= i){
            k += cnt[j];
        }
        if(k >= 2){
            int g = 0;
            for(int i = 0; i < n; i++){
                g = gcd(g, a[i]);
            }
            if(g == 1){
                cout << "setwise coprime" << endl;
            }else{
                cout << "not coprime" << endl;
            }
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
    
}


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

int main(){
    int n; double m; cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }
    sort(a.rbegin(), a.rend());

    double theta = sum/(4*m);
    rep(i, int(m)){
        if(a[i] < theta){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
ll sum, ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) {
        int a;
        cin >> a;
        sum += a;
        if (a == 0 || i == n-1) {
            ans += sum/2;
            sum = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };



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

	rep(i, 0, n) {
		cin >> a[i] >> b[i];
	}


	ll ans = -1;
	for (int i = 0; i <= 35; i++) {
		ll msk = 0;
		if (i == 0)msk = k;
		else {
			if ((1LL << i)&k) {
				for (int j = 0; j <= 35; j++) {
					if (j < i)msk += 1LL << j;
					else if (j > i && (k & (1LL << j)))msk += 1LL << j;
				}
			}
			else {
				continue;
			}
		}

		ll temp = 0;
		rep(p, 0, n) {
			int ok = 1;
			for (int j = 0; j <= 35; j++) {
				if ( ((1LL << j)&a[p]) && !((1LL << j)&msk) ) {
					ok = 0;
				}
			}
			if (ok)temp += b[p];
		}
		ans = max(ans, temp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <math.h>
int main()
{   
int K,N,i;
int worse=0;
scanf("%d %d",&K,&N);
int A[N];
int B[N];
for(i=0;i<N;i++){
scanf("%d",&A[i]);
    B[i]=A[i]-A[i-1];
    if(B[i]>worse){
    	worse=B[i];
    }
    }
    int z = K-A[N-1]+A[0];
    if(z>worse){
    	worse=z;
    }
printf("%d", K-worse);
    return 0;
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    string s;
    cin>>s;
    int n=s.length()+1;
    vector<int>v(n,0);
    for(int i=n-1;i>=1;i--)
    {
        if(s[i-1]=='>')
            v[i-1]=v[i]+1;
    }
    for(int i=1;i<n;i++)
    {
        if(s[i-1]=='<')
            v[i]=max(v[i],v[i-1]+1);
    }
    int sum=0;
    for(auto c:v)
       sum+=c;
    cout<<sum<<endl;
    return 0;
}

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

int N,u,v,w;
vector<pair<int,int> > G[100010];
int color[100010];

// 奇数だったら今とは違う色で塗る。
void dfs(int v, int pv, int c){
    color[v] = c;
    for(auto nv : G[v]){
        if(nv.first == pv) continue;
        dfs(nv.first, v, c^nv.second);
    }
}

int main(){
    cin >> N;
    REP(i,N-1){
        cin >> u >> v >> w;
        G[u].push_back(make_pair(v,w%2));
        G[v].push_back(make_pair(u,w%2));
    }
    dfs(1,0,0);
    REP(i,N) cout << color[i+1] << "\n";
    return 0;
}

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

int N,T;
int ans=0;
int A=0,B=0;

int main(){
  
  cin>>N>>T;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(B<x){
      ans+=(B-A);
      A=x;
      B=x+T;
    }else{
      B=x+T;
    }
  }
  ans+=(B-A);
  cout<<ans<<endl;
  return 0;
}


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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

const long long MOD = 1e9 + 7;
const int N = 3e6;
long long f[N];

long long power(long long a , long long b){
    long long x = 1 , y = a;
    while(b > 0){
        if(b & 1){
            x = (x * y);
            if(x > MOD)
                x %= MOD;
        }

        y = y*y;
        if(y > MOD)
            y %= MOD;

        b >>= 1;
    }
    return x;
}


long long nCr(long long n , long long r){
    return (f[n] * power(f[r] * f[n-r] %MOD , MOD - 2))% MOD;
}


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

    f[0] = 1;
    for(int i = 1 ; i < N ;i++)
        f[i] = (f[i-1] * i) % MOD;

    ll ans = 0;
    int x , y;
    cin >> x >> y;
    range(i,0,max(x,y)){
        int curx = x - i;
        int cury = y - 2*i;
        if(curx  < 0 || cury < 0)continue;
        if(curx % 2 == 0 && curx / 2 == cury){
            int mv = curx / 2;
            ans += nCr(i + mv , mv);
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 23680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int A=a/b;
		int B=a%b;
		double C;
		C=1.0*a/b;
			System.out.print(A+" "+B+" ");
			System.out.println(String.format("%.5f",C));
	}
}


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

template<class T> inline T gcd(T a, T b) {
    if (b == 0) return a;
    return  gcd(b, a % b);
}

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

    int n;
    cin >> n;

    int tmp;
    cin >> tmp;
    int g = gcd(tmp, tmp);
    REP(i, n - 1) {
        int tmp;
        cin >> tmp;
        g = gcd(g, tmp);
    }

    cout << g << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int t;
    bool flag = true;
    for(int i = 0; i < n;i++){
        cin >> t;
        if(t%2 == 0){
            if(t%3 == 0 || t%5 == 0){
            }else{
                flag = false;
            }
        }
    }
    if(flag)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        long H = Long.parseLong(scanner.next());
        long ans = 0;
        long cnt = 1;

        while (H >= 1) {
            ans += cnt;
            cnt *= 2;
            H /= 2;
        }

        System.out.println(ans);
    }
}


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

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	int dp[n];
	
	//cout<<dp[2]<<endl;
	for( int i=0;i<n;i++)
	{
		cin>>a[i];
		dp[i]=1000000000;
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for( int i=2;i<n;i++)
	{
		//dp[i]=min(abs(a[i]-a[0])+dp[0],dp[0]);
		for( int j=max(i-k,0);j<i;j++)
		{
			dp[i]=min(abs(a[i]-a[j])+dp[j],dp[i]);
		}
	}

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

}

Measured memory_bytes: 4360
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int num, i = 0, a, b, buf, bp, ans = 0;
	cin >> num;
	vector<int> d(2 * num), red(num), blue(num);
	vector<bool> ok(num, true);
	for (; i < num; i++) {
		scanf("%d%d", &a, &b);
		d[a] = b;
		red[i] = a;
	}
	for (i = 0; i < num; i++) {
		scanf("%d%d", &a, &b);
		d[a] = b;
		blue[i] = a;
	}
	sort(red.begin(), red.end());
	sort(blue.begin(), blue.end());
	for (b = 0; b < num; b++) {
		buf = -1;
		for (a = 0; a < num && red[a] < blue[b]; a++) {
			if (ok[a] && d[red[a]] < d[blue[b]] && d[red[a]] > buf) {
				buf = d[red[a]];
				bp = a;
			}
		}
		if (buf != -1) {
			ok[bp] = false;
			ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n");
    println(solve(input).trim());
  }

  def solve(input:String):String={
    val n=input.split("\n")(0).toInt
    val ds=input.split("\n")(1).split(" ").map(_.toInt)
    val a=(for (d1 <- ds; d2 <- ds) yield d1*d2).sum
    val b=ds.map(v=>v*v).sum
    ((a-b)/2).toString
  }
}


Measured memory_bytes: 25412
import java.util.*;
class Main{
  public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  long n=sc.nextInt();
  String output="";
  int i=1;
  if(n==0){
      System.out.println(0);
      return;
  }
  while(n!=0){
    if(n%Math.pow(2,i)!=0){
      output="1"+output;
      n-=(long)Math.pow(2,i-1)*(i%2==1?1:-1);
    }else{
      output="0"+output;
    }
    i++;
  }
    System.out.println(output);
  }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int a[110],n,ans=0;
    cin >> n;
    rep(i,n)cin >> a[i];
    sort(a,a+n,greater<int>());
    rep(i,n)ans+=a[i]*pow(-1,i);
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN=200100;
const int MAXK=16;
const int INF = 1e9;
const ll MOD = 1e9+7;

ll N,M,K,Q,u,v,w,a,b,c;
vpi V[MAXN];
vi A,B;

int main(){
	cin>>N;
	ll ans=0;
	for(int i=1;i<=N;++i){
		ll c=N/i;
		ll p=c*(c+1)*i/2;
		ans+=p;
	}
	cout<<ans;
}

Measured memory_bytes: 8316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#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 ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int r;
    cin >> r;
    cout << r*r << endl;
    return 0;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n,x;
	int ans;
	cin >> n >> x;
	std::vector<int> m(n);

	for (int i = 0; i < n; ++i)	cin >> m.at(i);
	std::vector<int>::iterator iter = std::min_element(m.begin(), m.end());
	auto index = std::distance(m.begin(), iter);

	x -= std::accumulate(m.begin(), m.end(), 0);
	ans = n + x / m.at(index);
	OUT(ans) BR;
	RET;
}


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

int main() {
    int k;
    std::cin >> k;

    int a[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    std::cout << a[k - 1] << std::endl;

    return 0;
}


Measured memory_bytes: 256
k = gets.to_s.to_i

q = (1..9).to_a

i = 1
while i < k

  n = q.shift
  i += 1
  
  d = n % 10
  s = d - 1
  s = 0 if s < 0
  t = d + 1
  t = 9 if 9 < t
  
  (s..t).each do |x|
    
    q.push( n * 10 + x )
  end
end

puts q[0]

Measured memory_bytes: 3784
from heapq import heappop, heappush
from collections import defaultdict

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

hp = []
for i, e in enumerate(a, 1):
    heappush(hp, [-e, i])

dp = defaultdict(int)
dp[(0, n + 1)] = 0
while hp:
    e, i = heappop(hp)
    e = -e
    dp2 = defaultdict(int)
    for k, v in dp.items():
        l, r = k
        dp2[(l + 1, r)] = max(dp2[(l + 1, r)], v + abs(l + 1 - i) * e)
        dp2[(l, r - 1)] = max(dp2[(l, r - 1)], v + abs(r - 1 - i) * e)

    dp = dp2

ans = max(dp.values())

print(ans)


Measured memory_bytes: 83844
t = list(str(input()).split(" "))
a = int(t[0])
b = int(t[1])

if(a < b):
    if(a == 1): print("Alice")
    else: print("Bob")
elif(b < a):
    if(b == 1): print("Bob")
    else: print("Alice")
else:
    print("Draw")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    string w;
    cin >> w;
    map<char, int> mp;
    for(int i = 0; i < w.size(); i++){
        ++mp[w[i]];
    }
    for(auto x : mp){
        if(x.second % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string.h>

using namespace std;
typedef pair<int, int> P;

int Par[100001];
int Rank[100001];

void init(long long n)
{
	for (int i = 0; i < n; ++i)
	{
		Par[i] = i;
		Rank[i] = 1;
	}
}

int find(int x)
{
	if (Par[x] == x)
	{
		return(x);
	}
	else
	{
		return(Par[x] = find(Par[x]));
	}
}

void unite(long long x, long long y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return;
	}
	if (Rank[x] < Rank[y])
	{
		Par[x] = y;
		Rank[y] += Rank[x];
	}
	else
	{
		Par[y] = x;
		//if (Rank[x] == Rank[y])
		//{
		//	++Rank[x];
		//}
		Rank[x] += Rank[y];
	}
}

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

void solve()
{
	long long N, M;
	cin >> N >> M;
	vector<long long> A(M);
	vector<long long> B(M);
	vector<long long> ans;
	init(N);
	long long sum = N * (N - 1) / 2;
	for (int i = 0; i < M; ++i)
	{
		cin >> A[i] >> B[i];
		--A[i];
		--B[i];
	}
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	for(int i = 0; i < M; ++i)
	{
		ans.push_back(sum);
		if(!same(A[i], B[i]))
		{
			sum = sum - Rank[find(A[i])] * Rank[find(B[i])];
		}
		unite(A[i], B[i]);
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); ++i)
	{
		cout << ans[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

vector<long> two(61);

void InitTwo(){
  two.at(0) = 1;
  rep(j,60){
    two.at(j+1) = 2*two.at(j);
    two.at(j+1) %= MOD; 
  }
}

int main(){
  int n;
  cin >> n;
  InitTwo();
  vector<long> c0(60,0);
  vector<long> c1(60,0);
  rep(i,n){
    long d;
    cin >> d;
    bitset<60> s(d);
    rep(j,60){
      if(s.test(j)) c1.at(j)++;
      else c0.at(j)++;
    }
  }
  long ans = 0;
  rep(i,60){
    long tmp = (c1.at(i)*c0.at(i))%MOD;
    ans += (tmp*two.at(i))%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


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

int main(){
    string s;
    cin >> s;

    int cnt = 0;
    int len = s.size();
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0 && s[i] == '0') cnt++;
        if(i % 2 != 0 && s[i] == '1') cnt++;
    }
    cout << min(cnt, len-cnt) << endl;
}

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

int main() {
    int N;
    long long int Y;
    cin >> N >> Y;

    for (int i=0; i<=N; ++i) {
        for (int j=0; j<=N-i; ++j) {
            int k = N - i - j;
            if (10000 * i + 5000 * j + 1000 * k == Y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            } 
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

ll N;
std::string S0;
bool fl;

int main()
{
  std::cin >> N;

  std::cout << 0 << std::endl;
  std::cin >> S0;

  if( S0 == "Vacant" )
  {
    return 0;
  }
  else
  {
    fl = S0=="Male"; 
  }

  ll ng = 0, ok = N;

  while( ok-ng > 1 )
  {
    ll mid = (ng+ok)/2;

    std::cout << mid << std::endl;

    std::string S;
    std::cin >> S;

    if( S == "Vacant" )
    {
      return 0;
    }

    if( (S == "Male") == (fl^(mid&1)) )
      ng = mid;
    else
      ok = mid;
  }

  return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

P p[200000];
int dp[300000];
vector<int>E[300000];

int main(){
	int n;cin>>n;
	vector<int>xs;
	rep(i,n){
		int x,l;scanf("%d%d",&x,&l);
		p[i].first=x-l;
		p[i].second=x+l;
		xs.push_back(p[i].first);
		xs.push_back(p[i].second);
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	rep(i,n){
		p[i].first=lower_bound(xs.begin(),xs.end(),p[i].first)-xs.begin();
		p[i].second=lower_bound(xs.begin(),xs.end(),p[i].second)-xs.begin();
		E[p[i].first].push_back(p[i].second);
	}
	rep(i,xs.size()){
		dp[i+1]=max(dp[i+1],dp[i]);
		for(int u:E[i]){
			dp[u]=max(dp[i],dp[i]+1);
		}
	}
	cout<<dp[xs.size()]<<endl;
}

Measured memory_bytes: 13172
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

now = 1
if 0 in A:
    print(0)
    exit()
for i in A:
    now *= i
    if now > 10 ** 18:
        print(-1)
        exit()
print(now)

Measured memory_bytes: 83224
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MAX_LEN 101

using namespace std;

void q15() {
	int N;
	scanf("%d\n", &N);
	for (int n = 0; n < N; n++) {
		string a, b;
		getline(cin, a);
		getline(cin, b);

		if (a.length() < b.length()) {
			string tmp = a;
			a = b;
			b = tmp;
		}

		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		
		int carry = 0;
		string ans="";

		int i = 0;
		for (; i < b.length(); i++) {
			ans+= (((a[i] - '0') + (b[i] - '0') + carry) % 10) + '0';
			carry = ((a[i] - '0') + (b[i] - '0') + carry) / 10;
		}
		for (; i < a.length(); i++) {
			ans+= (((a[i] - '0') + carry) % 10) + '0';
			carry = ((a[i] - '0') + carry) / 10;
		}
		for (; carry; i++) {
			ans+= (carry % 10) + '0';
			carry = carry / 10;
		}

		reverse(ans.begin(), ans.end());
		cout << (ans.length() > 80 ? "overflow" : ans) << endl;
	}
}
int main() {
	q15();
	return 0;
}

Measured memory_bytes: 3220
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    string s;
    getline(cin, s);
    //cout << s << endl;
    stack<int> st;
    int flg = 0;
    rep(i, s.size()) {
    
        if ('0' <= s[i] && s[i] <= '9') {
            if (flg) {
                int tmp = st.top();
                st.pop();
                st.push(tmp * 10 + (s[i] - '0'));
            } else {
                st.push(s[i] - '0');
            }
            flg = 1;
        } else {
            flg = 0;
            if (s[i] == ' ') {
                continue;
            }
            int a, b;
            b = st.top();
            st.pop();
            a = st.top();
            st.pop();
            int c;
            if (s[i] == '+') {
                c = a + b;
            } else if (s[i] == '-') {
                c = a - b;
            } else if (s[i] == '*') {
                c = a * b;
            }
            st.push(c);
        
        }
        //cout << st.top() << endl;
    }
    cout << st.top() << endl;
}



Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;
    char field[1005][1005];
    rep(i,0,H){
        rep(j,0,W){
            cin >> field[i][j];
        }
    }

    deque<pair<int,int>> que;
    int dist[1005][1005];
    const int INF = 1001001001;
    Fill(dist, INF);

    que.push_front({sx,sy});
    dist[sx][sy] = 0;
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int dx2[25] = {0,1,1,0,-1,-1,-1,0,1,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2};
    int dy2[25] = {0,0,1,1,1,0,-1,-1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1};
    while(!que.empty()){
        auto v = que.front();
        que.pop_front();
        rep(t,0,4){
            int nx = v.first + dx[t];
            int ny = v.second + dy[t];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W){
                if(field[nx][ny] == '.'){
                    
                    if(dist[nx][ny] > dist[v.first][v.second]){
                        dist[nx][ny] = dist[v.first][v.second];
                        que.push_front({nx,ny});
                    }
                }
            }
        }

        rep(t,0,25){
            int nx = v.first + dx2[t];
            int ny = v.second + dy2[t];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W){
                if(field[nx][ny] == '.'){
                    if(dist[nx][ny] > dist[v.first][v.second] + 1){
                        dist[nx][ny] = dist[v.first][v.second] + 1;
                        que.push_back({nx,ny});
                    }
                }
            }
        }
    }
  
    if(dist[gx][gy] < INF){
      cout << dist[gx][gy] << endl;
    }else{
      cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 8592
def gcd(a,b):
    if a>b: a,b=b,a
    while b:
        a, b = b, a%b
    return a

def lcm(a,b):
    if a==0: return b
    return a*b//gcd(a,b)

n = int(input())
a = list(map(int, input().split()))
g = 0
for i in range(n): g=lcm(g, a[i])

sm = 0
for i in a: sm += g//i
print(sm%1000000007)

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  LL n, maxw;
  vector<LL> v, w;
  vector<vector<LL>> dp;
  Solver2(LL n, LL maxw) : n(n), maxw(maxw), v(n + 1), w(n + 1), dp(n + 1, vector<LL>(100000 + 1, LINF)){};

  void solve() {
    for (int i = 1; i <= n; ++i) {
      cin >> w[i] >> v[i];
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
      for (int value = 0; value < v[i]; ++value) {
        dp[i][value] = dp[i - 1][value];
      }
      for (int value = v[i]; value <= 100000; ++value) {
        dp[i][value] = min(dp[i - 1][value], dp[i - 1][value - v[i]] + w[i]);
      }
    }
    int ans = 0;
    for (int i = 100000; i >= 0; --i) {
      if (dp[n][i] <= maxw) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, w;
  std::cin >> n >> w;

  Problem::Solver2 sol(n, w);
  sol.solve();
  return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int p,q,r;
  cin >> p >> q >> r;
  auto ans1 = 0; ans1 = p + q;
  auto ans2 = 0; ans2 = q + r;
  auto ans3 = 0; ans3 = p + r;
  cout << min({ans1,ans2,ans3}) << endl;
  return 0;
}



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

using namespace std;

int main()
{
	string s;
	cin >> s;
	bool flag = true;

	map<char, int> dic;
	for (int i = 0; i < s.size(); i++)
	{
		if (dic.count(s.at(i)))
		{
			flag = false;
			break;
		}
		else
		{
			dic[s.at(i)] = 1;
		}
	}

	if (flag)
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1e5 + 10;
int N;
int a[MAXN] , b[MAXN];
int ri1[MAXN];
int le1[MAXN];
int num[MAXN];

bool cmp(int n1 , int n2){
	if(a[n1] != a[n2])
		return a[n1] < a[n2];
	return b[n1] < b[n2];
}

int main(){
	ios::sync_with_stdio(0);
	cin >> N;
	for(int i = 1 ; i <= N ; ++ i)
		cin >> a[i] >> b[i];
	for(int i = 1 ; i <= N ; ++ i)
		num[i] = i;
	sort(num + 1 , num + N + 1 , cmp);
	int ans = 0;
	for(int i = 1 ; i <= N ; ++ i)
		ans = max(ans , b[i] - a[i] + 1);
	ri1[N] = b[num[N]];
	for(int i = N - 1 ; i >= 1 ; -- i)
		ri1[i] = min(ri1[i + 1] , b[num[i]]);
	le1[0] = 1e9 + 10;
	for(int i = 1 ; i <= N ; ++ i)
		le1[i] = min(le1[i - 1] , b[num[i]]);
	for(int i = 1 ; i < N ; ++ i)
		ans = max(ans , max(min(ri1[i + 1] , le1[i - 1]) - a[num[N]] + b[num[i]] - a[num[i]] + 2 , ri1[i + 1] - a[num[N]] + min(b[num[i]] , le1[i - 1]) - a[num[i]] + 2));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  char a[2][3];
  int n;
  int i;
  int j=0;

  while(1)
    {
      cin>>n;
      j=0;
      a[0][0]=a[1][0]=0;

      if(n==0)
        return 0;

      for(i=0;i<n;i++)
        {
          scanf("%s", a[i%2]);
          if(i%2==1)
            if(a[0][0]+a[1][0]=='r'+'l')
              j++;
        }

      printf("%d\n", j);
    }

  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

int main() {
    string s; cin >> s;
    vector<int> v(s.size());

    int odd = 0, even = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            swap(odd, even);
            even++;
        } else if (even + odd > 0) {
            v[i-1] += even;
            v[i] += odd;
            even = odd = 0;
        }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'L') {
            swap(odd, even);
            even++;
        } else if (even + odd > 0) {
            v[i+1] += even;
            v[i] += odd;
            even = odd = 0;
        }
    }

    for (int w : v) {
        cout << w << ' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1024