akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)

ll func(ll a, ll b){
    ll tmp, r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    ll tmp_a = a;
    ll tmp_b = b;
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return (tmp_a / b) * tmp_b;
}


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

    ll ans;
    ans = func(a,b);
    cout << ans << endl;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    int ans=0;
    for(auto p:mp){
        if(p.first>p.second) ans+=p.second;
        else ans+=p.second-p.first;
    }
    cout<<ans;
}

Measured memory_bytes: 10048
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

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

  if (s.length() <= k)
  {
    cout << s;
  }
  else
  {
    cout << s.substr(0, k) << "...";
  }

  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> vec(n, 0);
  for(int i = 0; i < n; ++i){
    cin>>vec[i];
  }
  int res = 0;
  int cnt = 1;
  for(int i = 0; i < n; ++i){
    if(vec[i] == cnt){
      cnt++;
    }
    else res++;
  }
  if(res == n)cout<<-1<<endl;
  else cout<<res<<endl;  
  return 0;
}

//1 1 1 1


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
	long max = -1000000;
	long min = 1000000;
	long sum = 0;
	long a;
	int i, n;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%ld", &a);
		if (max < a) {
			max = a;
		}

		if (min > a) {
			min = a;
		}

		sum += a;
	}

	printf("%ld %ld %ld\n", min, max, sum);

	return 0;

}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );

		while(str.contains("BB") || str.contains("WW")){
			if(str.contains("BB")){
				str = str.replace("BB", "B");
			}else{
				str = str.replace("WW", "W");
			}
		}
		System.out.println(str.length()-1);

	}
}


Measured memory_bytes: 33588
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	n, m = rli()
	seen = defaultdict(lambda: False)
	G = [[] for _ in range(n)]
	for _ in range(m):
		u, v = rli()
		u -= 1
		v -= 1
		u, v = min(u, v), max(u, v)
		if seen[(u, v)]: continue
		seen[(u, v)] = True
		G[u].append(v)
		G[v].append(u)
	sizes = []
	seen2 = defaultdict(lambda: False)
	loc_size = 0
	def dfs(node):
		nonlocal loc_size 
		seen2[node] = True
		loc_size += 1
		for nbhr in G[node]:
			if seen2[nbhr]: continue
			dfs(nbhr)

	for i in range(n):
		if seen[i]: continue
		loc_size = 0
		dfs(i)
		sizes.append(loc_size)
	print(max(sizes))
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 655504
extern crate proconio;
use proconio::{fastout, input, marker::Usize1};

use std::cmp;
use std::collections;

struct State<T>(u64, T);

impl<T> cmp::PartialEq for State<T> {
    fn eq(&self, other: &Self) -> bool {
        self.0 == other.0
    }
}

impl<T> cmp::Eq for State<T> {}

impl<T> cmp::PartialOrd for State<T> {
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T> cmp::Ord for State<T> {
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        s: u32,
        es: [(Usize1, Usize1, usize, u64); m],
        vs: [(u32, u64); n],
    }
    let lim = es.iter().map(|&(_, _, a, _)| a).max().unwrap() * (n - 1) + 1;
    let s = cmp::min(s, (lim - 1) as u32) as usize;
    let vs = vs.into_iter()
        .map(|(c, d)| (cmp::min(c, (lim - 1) as u32) as usize, d))
        .collect::<Vec<_>>();
    let mut heap = collections::BinaryHeap::new();
    let mut g = vec![Vec::new(); n];
    for (u, v, a, b) in es {
        g[u].push((v, a, b));
        g[v].push((u, a, b));
    }

    let mut dist = vec![std::u64::MAX; n * lim];
    dist[0 * lim + s] = 0;
    heap.push(State(0, 0 * lim + s));
    while let Some(State(t, i)) = heap.pop() {
        let v = i / lim;
        let k = i % lim;
        if dist[i] < t {
            continue;
        }
        {
            let &(c, d) = &vs[v];
            let p = cmp::min(k + c, lim - 1);
            let j = v * lim + p;
            if t + d < dist[j] {
                dist[j] = t + d;
                heap.push(State(dist[j], j));
            }
        }
        for &(u, a, b) in &g[v] {
            if k >= a {
                let j = u * lim + k - a;
                if t + b < dist[j] {
                    dist[j] = t + b;
                    heap.push(State(dist[j], j));
                }
            }
        }
    }
    for t in 1..n {
        println!(
            "{}",
            dist[t * lim..t * lim + lim].iter().copied().min().unwrap()
        );
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i = 0; i < N; i++) cin >> L.at(i);
  int c = 0;
  
  for(int i = 0; i < N-2; i++){
    for(int j = i + 1; j < N-1; j++){
      for(int k = j + 1; k < N; k++){
        if((L.at(i) != L.at(j)) && (L.at(j) != L.at(k)) && (L.at(k) != L.at(i)) && (L.at(i) < L.at(j) + L.at(k)) && (L.at(j) < L.at(i) + L.at(k)) && (L.at(k) < L.at(i) + L.at(j))) c++;
      }
    }
  }
  
  cout << c << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N;
	int sum = 0;
	scanf("%d", &N);
	int A[30], B[30], C[30];
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &B[i]);
	}
	for (int i = 0; i < N-1; i++) {
		scanf("%d", &C[i]);
	}
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			sum += B[A[i]-1];
		}
		else {
			sum += B[A[i]-1];
			if (A[i] - A[i - 1] == 1) {
				sum += C[A[i]-2];
			}
		}

	}
	printf("%d", sum);

	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    a94(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a94(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (cat, either, x) = args[0].split(" ").map { it.toInt() }
    println(if (x in (cat..(cat + either))) "YES" else "NO")
}

Measured memory_bytes: 38252
n = int(input())
n1000 = n//1000
na = n-1000*n1000
n100 = na//100
nb=na-100*n100
n10=nb//10
nc=nb-10*n10
c = 0
if n1000 ==2:
    c += 1
if n100 ==2:
    c += 1
if n10 ==2:
    c+=1
if nc ==2:
    c+=1
print(c)


Measured memory_bytes: 3316
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 3e5 + 10, mlg = 20, mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	if(n>9) {
		cout << k << '\n';
	} else {
		cout << k + 100*(10-n);
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

void solve() {
    int n, m;
    cin >> n >> m;
    int a, b;
    VP p;
    REP(i, 0, m) {
        cin >> a >> b;
        p.pb(a, b);
    }
    sort(all(p), [](auto &l, auto &r) { return l.second < r.second; });
    int la = -1;
    int cnt = 0;
    REP(i, 0, m) {
        int l = p[i].first;
        int r = p[i].second;
        if (l < la)
            continue;
        ++cnt;
        la = r;
    }
    cout << cnt << endl;
}

signed main() {
    solve();

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<string>
#include<utility>
using namespace std;
typedef pair<int, int> P;

vector<P> run_length(string& S) {
    char now = S[0];
    int cnt = 1;
    vector<P> res;
    for (int i = 1; i < S.size(); ++i) {
        if (now == S[i]) cnt++;
        else {
            res.push_back(P(now, cnt));
            now = S[i];
            cnt = 1;
        }
    }
    res.push_back(P(now, cnt));
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    vector<P> comp_arr = run_length(S);
    vector<int> ans(S.size(), 0);
    int start = 0;
    for (int i = 0; i < comp_arr.size(); i += 2) {
        int r_cnt = comp_arr[i].second;
        int l_cnt = comp_arr[i + 1].second;
        int r_ans = (r_cnt + 1) / 2 + l_cnt / 2;
        int l_ans = r_cnt / 2 + (l_cnt + 1) / 2;
        int r_pos = start + r_cnt - 1;
        int l_pos = start + r_cnt;
        ans[r_pos] = r_ans;
        ans[l_pos] = l_ans;
        start = start + r_cnt + l_cnt;
    }
    for (int i = 0; i < S.size(); ++i) cout << ans[i] << ' ';
    cout << endl;
    return 0;
}

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

int main(){
  long N;
  cin >> N;
  long a=N,b=0;
  for(long i=1;i<=sqrt(N);i++){
    if(N%i==0){
      b = (i-1) + (N/i-1);
      a = min(a,b);
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
def trace(a)
  n = a.length
  i = 0
  while i < n do
    print " " if i > 0
    print "#{a[i]}"
    i += 1
  end
  puts ""
end

def insertion_sort(a)
  n = a.length
  i = 1
  while i < n do
    v = a[i]
    j = i - 1
    while j >= 0 && a[j] > v do
      a[j + 1] = a[j]
      j -= 1
    end
    a[j + 1] = v
    trace(a)
    i += 1
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

trace(a)
insertion_sort(a)



Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main(){
 long long n,d;
 cin >> n >> d;
 vector<long long > x(n),y(n);
 int ans = 0;
 for(long i= 0;i<n;i++){
    cin >> x[i] >> y[i];
    if(sqrt(x[i]*x[i]+y[i]*y[i])<=d){
       ans ++;
    }
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, W;
  cin >> N >> W;
  ll sum_w = N * 3;
  vector<vector<ll>> it;
  ll w1;
  for (ll i = 0; i < N; ++i) {
    ll w, v;
    cin >> w >> v;
    if (i == 0) {
      w1 = w;
    }
    it.push_back({w - w1, v});
  }
  // now, w, used
  vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(sum_w + 1, vector<ll>(N + 1, 0)));
  for (ll i = 0; i < N; ++i) {
    for (ll j = 0; j < sum_w; ++j) {
      for (ll k = 0; k < N; ++k) {
        dp.at(i + 1).at(j).at(k) = max(dp.at(i + 1).at(j).at(k), dp.at(i).at(j).at(k));
        if (j + it.at(i).at(0) <= sum_w) {
          dp.at(i + 1).at(j + it.at(i).at(0)).at(k + 1) = max(dp.at(i + 1).at(j + it.at(i).at(0)).at(k + 1), dp.at(i).at(j).at(k) + it.at(i).at(1));
        }
      }
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= N; ++i) {
    // cout << "i" << i << "\n";
    for (ll j = 0; j <= sum_w; ++j) {
      // cout << "j" << j << "\n";
      for (ll k = 0; k <= N; ++k) {
        if (j + k * w1 <= W) {
          ans = max(ans, dp.at(i).at(j).at(k));
        }
        // cout << dp.at(i).at(j).at(k) << " ";
      }
      // cout << "\n";
    }
    // cout << "\n";
  }
  cout << ans << "\n";
}


Measured memory_bytes: 28520
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])
    cout<<"Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int n;
    cin>>n;
    int a[21];
    int b[21];
    int c[21];
    map<int,int> mp;
    rep2(1,i,n+1){
        cin>>a[i];
        
    }
    int sum=0;
    rep2(1,i,n+1){
        cin>>b[i];
        sum+=b[i];
    }
    rep2(1,i,n)cin>>c[i];
    for(int i=1;i<=n-1;i++){
        //cout<<a[i]<<" "<<a[i+1]<<endl;
        if(a[i+1]==a[i]+1){
            sum+=c[a[i]];
        }
        
    }

    
    int ans=sum;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    string s, t;    cin >> s >> t;
    int ans = 0;
    if (s[0] == t[0])   ++ans;
    if (s[1] == t[1])   ++ans;
    if (s[2] == t[2])   ++ans;

    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
HList = [int(i) for i in input().split(" ")]
stn = -1
count = 0

for i in range(len(HList)) :
    if HList[i] >= stn  :
        count += 1
    if stn < HList[i] :
        stn = HList[i]

print(count)

Measured memory_bytes: 3060
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

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

    ll n,k,m;
    cin>>n>>k>>m;
    ll a[n+1];
    ifr(i,0,k) a[i]=m;
    for(int i=k;i<n;i++) a[i]=((m==1)?2:m-1);
    ifr(i,0,n) cout<<a[i]<<" ";cout<<endl;
    return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)


class SEGMENTS{
private:
    
    struct seg{
        int l,r;
        bool operator < (seg obj)const {
            if(r!=obj.r) return r<obj.r;
            else return l<obj.l;
        }
    };
    
    set<seg> dat;
    
    bool isCross(int l1,int r1,int l2,int r2){ return ( (l1<=l2 && l2<r1) || (l2<=l1 && l1<r2)); }
    bool isInclude(int li, int ri, int L, int R){ return (L<=li && ri<=R); }
    
public:
    
    void erase(int l, int r){
        while(true){
            auto it = dat.upper_bound(seg{(int)INF,l});
            if(it==dat.end())break;
            
            int li = it->l;
            int ri = it->r;
            if( !isCross(li,ri,l,r) )break;
            
            if( isInclude(li,ri,l,r) ) dat.erase(it);
            else{
                int tl = li, tr = ri;
                if( isInclude(l,r,li,ri) ){
                    dat.erase(it);
                    if(li!=l) dat.insert(seg{li,l});
                    if(r!=ri) dat.insert(seg{r,ri});
                }else{
                    if(li<=l&&l<ri) tr = l;
                    if(l<=li&&li<r) tl = r;
                    dat.erase(it);
                    if(tl!=tr) dat.insert(seg{tl,tr});
                }
            }
        }
    }
    
    void insert(int l, int r){
        while(true){
            auto it = dat.upper_bound(seg{(int)INF,l});
            if(it==dat.end() || r<it->l)break;
            
            if( isInclude(it->l,it->r,l,r) ) dat.erase(it);
            else{
                l = min(l,it->l);
                r = max(r,it->r);
            }
        }
        
        auto it = dat.lower_bound(seg{(int)-INF,l});
        if( it!=dat.end() && it->r == l ){
            l = it->l;
            dat.erase(it);
        }
        
        if(l!=r)dat.insert(seg{l,r});
    }
    
    int size(){ return dat.size(); }
    
    void output(){ for(auto e:dat)cout<<e.l<<" "<<e.r<<endl;cout<<endl; }
};

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    SEGMENTS st;
    
    for(int i=0;i<n;){
        if(s[i]=='0')i++;
        else{
            int l=i;
            while(i<n && s[i]=='1') i++;
            st.insert(l,i);
        }
    }
    
    int q;
    cin>>q;
    while(q--){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        
        if(b==0)    st.erase(l,r);
        else        st.insert(l,r);
        
        cout<<st.size()<<endl;
    }
}

Measured memory_bytes: 4168
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int ofs = 10, lim = 10;
ll dp[200010][25][2];

int main() {
    int N; scanf("%d", &N);
    vector<ll> A(N);
    for(int i=0; i<N; i++) scanf("%lld", &A[i]);

    fill(dp[0][0], dp[N+1][0], -LONGINF);
    dp[0][ofs][0] = 0;
    for(int i=0; i<N; i++) {
        for(int j=0; j<=2*lim; j++) {
            for(int k=0; k<2; k++) {
                int tj = j - ofs;
                if(!k) {
                    if(abs(tj+1) > lim) continue;
                    int nj = (tj+1) + ofs;
                    chmax(dp[i+1][nj][1], dp[i][j][k] + A[i]);
                }
                {
                    if(abs(tj-1) > lim) continue;
                    int nj = (tj-1) + ofs;
                    chmax(dp[i+1][nj][0], dp[i][j][k]);
                }
            }
        }
    }
    cout << max(dp[N][ofs-(N%2)][0], dp[N][ofs-(N%2)][1]) << endl;
    return 0;
}


Measured memory_bytes: 83012
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		int Num;

		Scanner sc = new Scanner(System.in);

		Num = sc.nextInt();

		int[] NumArray = new int[Num];

		for (int i = 0; i < Num; i++) {

			NumArray[i] = sc.nextInt();

		}

		int count = 0;

		for (int i = 1; i < NumArray.length; i++) {

			if (NumArray[i-1] < NumArray[i]) {

				++count;
				NumArray[i] = NumArray[i] -1;

			} else if (NumArray[i-1] == NumArray[i]) {

				++count;

			} else {
				break;
			}

		}

		if (count == NumArray.length -1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

using namespace std;

using i64 = int64_t;

using real_t = long double;

struct line {
  real_t k, b;

  real_t apply(real_t x) const {
    return k * x + b;
  }
};

struct segment {
  real_t from, to;

  bool inside(real_t x) const {
    return from <= x && x <= to;
  }
};

real_t inter(line const& a, line const& b) {
  return (a.b - b.b) / (b.k - a.k);
}

struct cht {
  real_t const INF = 1e7;
  vector<pair<line, segment>> lines;
  int ptr = 0;

  void add_line(line const& l) {
    while (lines.size() >= 2) {
      auto x_my = inter(l, lines.back().first);
      auto x_they = inter(lines.back().first, lines[lines.size() - 2].first);
      if (x_my <= x_they) {
        lines.pop_back();
      } else {
        break;
      }
    }
    if (lines.empty()) {
      lines.emplace_back(l, segment{-INF, INF});
    } else {
      auto x = inter(lines.back().first, l);
      lines.back().second.to = x;
      lines.emplace_back(l, segment{x, INF});
    }
  }

  real_t get(real_t x) {
    while (!lines[ptr].second.inside(x)) {
      ++ptr;
    }
    assert(ptr < lines.size());
    return lines[ptr].first.apply(x);
  }
};

int main() {
#ifdef GOLIKOV
  freopen("in", "rt", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  real_t c;
  cin >> n >> c;
  cht hull;
  vector<real_t> dp(n);
  for (int i = 0; i < n; ++i) {
    real_t h;
    cin >> h;
    if (i) {
      dp[i] = h * h + c + hull.get(h);
    }
    line l{-2 * h, h * h + dp[i]};
    hull.add_line(l);
  }
  cout << (i64) dp.back() << '\n';
  return 0;
}


Measured memory_bytes: 21608
use std::cmp::min;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let q: i64 = read();
    let h: i64 = read();
    let s: i64 = read();
    let d: i64 = read();
    let n: i64 = read();

    let one = *[q * 4, h * 2, s].iter().min().unwrap();
    let two = min(one * 2, d);

    println!("{}", n / 2 * two + n % 2 * one);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 0; i < 101; i++) {
        if (i%2 == 1) {
            a -= d;
        } else {
            c -= b;
        }
        if (a <= 0 || c <= 0) {
            break;
        }
    }
    if (a <= 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

long long a[3], b[3];
long long dp[25000010];

int main(){
	long long n; cin >> n;
	for (int i = 0; i < 3; i++){
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++){
		cin >> b[i];
	}
	for (int i = 0; i <= n; i++){
		dp[i] = -0x3f3f3f3f;
	}
	dp[0] = 0;
	for (int i = 0; i < 3; i++){
		for (int j = a[i]; j <= n; j++){
			dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
		}
	}
	long long maxj = 0;
	for (int i = 0; i <= n; i++){
		maxj = max(maxj, n - i + dp[i]);
	}
	n = maxj;
	for (int i = 0; i <= n; i++){
		dp[i] = -0x3f3f3f3f;
	}
	dp[0] = 0;
	for (int i = 0; i < 3; i++){
		for (int j = b[i]; j <= n; j++){
			dp[j] = max(dp[j], dp[j - b[i]] + a[i]);
		}
	}
	maxj = 0;
	for (int i = 0; i <= n; i++){
		maxj = max(maxj, n - i + dp[i]);
	}
	cout << maxj << endl;
	return 0;
}


Measured memory_bytes: 195584
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		List<Integer> in = new ArrayList<Integer>();
		while(sc.hasNextInt()) {
			in.add(sc.nextInt());
		}
		Queue<Car> out = out(in);
		for(Car c: out) System.out.println(c.num);
		sc.close();
	}
	
	static Queue<Car> out(List<Integer> args){
		LinkedList<Car> replace = new LinkedList<Car>();
		Queue<Car> out = new LinkedList<Car>();
		for(int i: args) {
			if(i == 0) out.add(replace.pollLast());
			else replace.add(new Car(i));
		}
		return out;
		
	}
}

class Car{
	int num;
	Car(int num){
		this.num = num;
	}
	
}

Measured memory_bytes: 17220
/*
 * main.cpp
 *
 *  Created on: 2019/03/19
 *      Author: maleicacid
 */

#include <climits>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>

#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tag_and_trait.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
class UnionFind
{
public:
	gp_hash_table<T, long> sz;
	gp_hash_table<T, long> rank;
	UnionFind()
	{

	}
	~UnionFind()
	{
		sz.clear();
		rank.clear();
		m.clear();
	}
	void makeSet(long value)
	{
		m[value] = value;
		sz[value] = 1;
		rank[value] = 0;
	}

	T findSet(T x)
	{
		auto tmp = m.find(x);

		if (tmp != m.end())
		{
			if (x != (*tmp).second)
			{
				return (*tmp).second = findSet((*tmp).second);
			}
			return (*tmp).second;
		}
	}
	bool isEqual(T x, T y)
	{
		return findSet(x) == findSet(y);
	}

	long unite(T x, T y)
	{
		auto p = pair<T,T>(findSet(x), findSet(y));
		if (p.first != p.second)
		{
			auto t = link(p.first, p.second);
			return t.first * t.second;
		}
		else
			return 0;
	}

private:
	gp_hash_table<T, T> m;
	pair<const long, const long> link(T x, T y)
	{
		pair<const long, const long> tmp(sz[x], sz[y]);
		if (sz[x] > sz[y])
		{
			m[y] = x;
			sz[x] += sz[y];
			sz.erase(y);
		}
		else
		{
			m[x] = y;
			if (sz[y] == sz[x])
				rank[y]++;
			sz[y] += sz[x];
			sz.erase(x);
		}
		return tmp;
	}
};


int main()
{
	int n, m;
	scanf("%d",&n);
	scanf("%d",&m);

	stack<pair<long, long>> g;
	for (int i = 0; i < m; i++)
	{
		long a, b;
		scanf("%ld", &a);
		scanf("%ld",&b);

		pair<long, long> p(a,b);
		g.push(p);
	}

	UnionFind<long> graph;

	for (int i = 1; i <= n; i++)
		graph.makeSet(i);

	vector<long> inconvenience;
	inconvenience.push_back(0);
	for (int i = 0; i < m; i++)
	{
		auto p = g.top();
		g.pop();
		auto a = graph.unite(p.first, p.second);
		inconvenience.push_back(a +inconvenience[i]);
	}

	for (int i = m-1; i >= 0; i--)
		printf("%ld\n", inconvenience[m] - inconvenience[i]);
}

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

#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double ld;

const ld pi=3.1415926535897932384626433;
const int mod = 1000000007;
const ll inf=3e18;
// 90DTG
ll dp[100001];
ll h[100001];
ll k=2;
ll n;

ll god(ll i)
{
   if (i>n)
      return inf;
   if (i==n)
      return 0;
   if (dp[i]!=-1)
      return dp[i];

   ll ans=inf;
   for (ll j=i+1;j<=min(i+k,n);j++)
   {
      ans=min(ans,abs(h[i]-h[j])+god(j));
   }
   return dp[i]=ans;
}
int main ()
{
   bolt;
   memset (dp,-1,sizeof(dp));
   cin>>n;
   for (ll i=1;i<=n;i++)
   {
      cin>>h[i];
   }
   cout<<god(1);

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	int A,B,C;
	cin>>A>>B>>C;
	
	if(B-A==C-B) puts("YES");
	else puts("NO");

	return 0;
}



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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); \
                cin.tie(0); \
                cout.tie(0)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(_v)             _v.begin(), _v.end()
#define sz(_v)              (int) _v.size()
#define first(_obj)         (*_obj.begin())
#define last(_obj)          (*prev(_obj.end()))
#define FIND(_obj, _val)    (_obj.find(_val) != _obj.end())
#define RESET(_a, _v)       fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define REP(_i, _n)         for (int _i = 0; _i < (int) _n; _i++)
#define FOR(_i, _a, _b)     for (int _i = (int) _a; _i <= (int) _b; _i++)
#define FORD(_i, _a, _b)    for (int _i = (int) _a; _i >= (int) _b; _i--)
#define FORIT(_it, _obj)    for (auto _it = _obj.begin(); _it != _obj.end(); _it++)

// DEBUG UTIL
template<typename TF>
void debug(ostream &out, TF const &f) {
    out << f << std::endl;
}
 
template<typename TF, typename ... TR>
void debug(ostream &out, TF const &f, TR const& ... rest) {
    out << f << " ";
    debug( out, rest... );
}
 
#define DEBUG(...) debug(cerr, "[", #__VA_ARGS__, "]:", __VA_ARGS__)

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
using vs = vector<string>;

const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1}; // ccw
const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1};
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1073741823;
const ll INFLL = 4e18;
const int MAX = 3e3;

int N, arr[MAX+5];
ll dp[MAX+5][MAX+5][2];

void read() {
    cin >> N;
    REP(i, N) cin >> arr[i];
}

ll solve(int i, int j, bool p) {
    if (j < i) return 0;

    ll &ret = dp[i][j][p];
    if (ret != -1) return ret;

    if (!p) { // maximize X - Y, play as X
        ret = max(arr[i] + solve(i + 1, j, p ^ 1), arr[j] + solve(i, j - 1, p ^ 1));
    } 
    else { // minimize X - Y, play as Y
        ret = min(-arr[i] + solve(i + 1, j, p ^ 1), -arr[j] + solve(i, j - 1, p ^ 1));
    }

    return ret;
}

void solve() {
    memset(dp, -1, sizeof dp);
    cout << solve(0, N - 1, 0) << "\n";
}

int main() {
    FAST_IO;
    int TC = 1;
    FOR(tc, 1, TC) {
        read();
        solve();
    }
}

Measured memory_bytes: 141568
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((abs(b-a)<=d&&abs(c-b)<=d)||abs(c-a)<=d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

int A, B, C, K;

int maiorsoma(int a, int b, int c){
    int soma1 = 0, soma2 = 0, soma3 = 0;
    soma1+=2*a + b + c;
    soma2+=a + 2*b+ c;
    soma3+= a + b + 2*c;
    if(max(soma1, max(soma2, soma3)) == soma1) A *= 2;
    else if(max(soma1, max(soma2, soma3)) == soma2) B*= 2;
    else C*= 2;

    return max(soma1, max(soma2, soma3));
}

int main(){
    int resp = 0;
    cin >> A >> B >> C >> K;
    for ( int i = 0; i < K; ++i ) {
        resp= maiorsoma(A, B, C);
    }
    cout << resp;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int m;
	cin >> m;
	for (int i = sqrt(m + 1); i >=1 ; i--) {
		if (m % i == 0)
			if (m / i < 10 && i < 10) {
				cout << "Yes";
				return 0;
			}
			else {
				cout << "No";
				return 0;
			}
		
	}
}

Measured memory_bytes: 256
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

s = ns()
k = ni()

c = 0
ans = 1
for i in range(len(s)):
    if s[i] == '1':
        c += 1
    else:
        if c >= k:
            break
        else:
            ans = s[i]
            break

print(ans)

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  
  if (N % X) {
    cout << T * (N/X + 1) << endl; 
  } else {
    cout << T * (N/X) << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size): data(size,-1) {
    }
    
    int root(int x){
        return (data[x] < 0)? x : data[x]=root( data[x] );
    }
    
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if( x != y ){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    
    bool find(int x, int y){
        return root(x) == root(y);
    }
    
    int size(int x){
        return -data[ root(x) ];
    }
};

int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    rep(i,n) {
        int a;
        cin>>a;
        a--;
        vec[a]=i+1;
    }
    
    rep(i,n) cout<<vec[i]<<endl;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <queue>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
typedef struct {
    int plus, pos;
} Dungeon;
 
bool operator < (const Dungeon &a, const Dungeon &b)
{
    if (a.plus != b.plus){
        return (a.plus < b.plus);
    }
    else {
        return (a.pos < b.pos);
    }
}
int data[1 << 18], datb[1 << 18];

int getMax(int a, int b, int k, int l, int r)
{
	if (b <= l || r <= a) return (0);
	if (a <= l && r <= b){
		return (data[k] + datb[k]);
	}
	
	int lch = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
	int rch = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
	
	return (max(lch, rch) + datb[k]);
}

void add(int a, int b, int x, int k, int l, int r)
{
	if (b <= l || r <= a) return;
	
	if (a <= l && r <= b){
		datb[k] += x;
		while (k){
			k = (k - 1) / 2;
			data[k] = max(data[k * 2 + 1] + datb[k * 2 + 1], data[k * 2 + 2] + datb[k * 2 + 2]);
		}
	}
	else {
		add(a, b, x, k * 2 + 1, l, (l + r) / 2);
		add(a, b, x, k * 2 + 2, (l + r) / 2, r);
	}
}

int main(void)
{
    int N, H;
    int di[100000], hi[100000];
    int curLife;
     
    scanf("%d %d", &N, &H);
    
    for (int i = 0; i < N - 1; i++){
        scanf("%d %d", &di[i], &hi[i]);
    }
     
    curLife = H;
     
    ll ans = 0;
    priority_queue<Dungeon> que;
    for (int i = 0; i < N - 1; i++){
		add(i, i + 1, curLife, 0, 0, 1 << 17);
        Dungeon in;
        curLife -= di[i];
         
        in.plus = hi[i];
        in.pos = i;
         
        que.push(in);
        while (curLife <= 0){
            Dungeon heal = que.top();
            que.pop();
            
            int segMax = getMax(heal.pos, i + 1, 0, 0, 1 << 17);
             
            if (heal.plus + segMax > H){
                heal.plus = H - segMax;
                que.push(heal);
                continue;
            }
             
            int howMany = min((-1 * curLife) / heal.plus + 1, (H - segMax) / heal.plus);
            ans += howMany;
            curLife += howMany * heal.plus;
             
            add(heal.pos, i + 1, howMany * heal.plus, 0, 0, 1 << 17);
            que.push(heal);
        }
    }
     
    printf("%lld\n", ans);
     
    return (0);
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

int main() {
	ios::sync_with_stdio(false);

	ll n; cin >> n;

	vl a(n);

	vvl dp(n, vl(n+1, 0));
	FOR(i,0,n) {
		cin >> a[i];
	}

	FOR(j,1,n+1) {
		FOR(i,0,n) {
			ll x = i;
			ll y = i + j;
			if (y > n) {
				continue;
			}
			if (i+1 >= n) {
				dp[i][j] = a[y-1] - dp[i][j-1];
			} else {
				dp[i][j] = max(a[x] - dp[i+1][j-1], a[y-1] - dp[i][j-1]);
			}
		}
	}

	cout << dp[0][n] << endl;

	return 0;
}


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll Fa[1020101], iFa[1020101];

void init(){
    ll i;
    Fa[0] = 1;
    rep(i,0,1010101){
        Fa[i + 1] = Fa[i] * (i + 1) % MOD;
    }
    iFa[i] = moddiv(1, Fa[i]);
    for (i = 1010101; i > 0;--i){
        iFa[i - 1] = iFa[i] * i % MOD;
    }
}
ll C(ll a,ll b){
    if(a<b)
        return 0;
    return Fa[a] * iFa[b] % MOD * iFa[a - b] % MOD;
}




ll N,M;

ll mk[505050];
ll i, j, k;

int main(){
    scanf("%lld%lld", &N, &M);
    init();
    mk[0] = Fa[N] * C(M, N) % MOD;
    rep(i,0,N){
        ll a = C(N, i + 1) * Fa[N - 1 - i] % MOD * C(M - 1 - i, N - 1 - i) % MOD;
        //printf("%lld  ", a);
        if(i%2==0){
            (mk[i + 1] = mk[i]+MOD - a) %= MOD;
        }else{
            (mk[i + 1] = mk[i] + a) %= MOD;
        }
        //printf("%lld\n", mk[i + 1]);
    }
    printf("%lld\n", mk[N] * mk[0] % MOD);
    return 0;
}

Measured memory_bytes: 23272
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,k;
    scanf("%lld",&n);
    long long int ar[n+6][5],dp[n+6][5],max1=0;
    memset(ar,0,sizeof(ar[0][0])*(n+6)*5);
    memset(dp,0,sizeof(dp[0][0])*(n+6)*5);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=3;j++)
        {
            scanf("%lld",&ar[i][j]);
        }
    }
    dp[1][1]=ar[1][1],dp[1][2]=ar[1][2],dp[1][3]=ar[1][3];
    for(i=2;i<=n;i++)
    {
        for(j=1;j<=3;j++)
        {
            for(k=1;k<=3;k++)
            {
                if(k!=j)
                dp[i][j]=max(dp[i-1][k]+ar[i][j],dp[i][j]);
            }
        }
    }
    for(i=1;i<=3;i++)
    {
        max1=max(max1,dp[n][i]);
    }
    printf("%lld\n",max1);
}


Measured memory_bytes: 8064
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var line1 = Console.ReadLine().Split();
        var N = int.Parse(line1[0]);
        var X = int.Parse(line1[1]);
        var m = new int[N];
        for (int i=0; i<N; i++)
        {
            m[i] = int.Parse(Console.ReadLine());
        }
        var answer = N + ( X - m.Sum() ) / m.Min();
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
bool primes[1000001];vi prime; void seive(); int gcd(int a, int b); int power(int x, int y);

int32_t main(void){
	IOS;
	in1(t);
	if(t >= 30) cout<<"Yes\n";
	else cout<<"No\n";
}

void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}
int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}
int power(int x, int y){ int res = 1;x = x % mod; if (x == 0) return 0;
while (y > 0){ if(y & 1) res = (res*x) % mod; y = y>>1; x = (x*x) % mod;} return res;}


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

using namespace std;

int calc(int X, int n, int *p)
{
    int ans = 102;
    int mindiff = 102;
    for (int i = 0; i <= 101; i++)
    {
        int diff = abs(i - X);
        if (mindiff > diff)
        {
            int cnt = 0;
            for (int j = 0; j < n; j++)
            {
                if (p[j] == i)
                {
                    cnt++;
                }
            }

            if (cnt == 0)
            {
                mindiff = diff;
                ans = i;
            }
        }
    }

    return ans;
}

int main()
{
    int X, N;
    cin >> X >> N;

    int p[N];
    for (size_t i = 0; i < N; i++)
    {
        cin >> p[i];
    }

    auto answer = calc(X, N, p);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
 
int main(void){
  long long N, A, B;
  cin >> N >> A >> B;
  long long temp = N / (A + B);
  long long s = N % ( A + B);
  if(s > A) cout << A * (temp + 1);
  else cout << A * temp + s;
  return 0;
}

Measured memory_bytes: 256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int cnt[12][12];

int main(){
	int n=ci();
	rep(i,1,n){
		int x=i;
		while( x>=10 ) x/=10;
		cnt[x][i%10]++;
	}
	ll ans = 0;
	rep(i,1,9) rep(j,1,9) ans+= 1ll*cnt[j][i]*cnt[i][j];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 760
n,b,f[50001];main(a){for(;++a<50001;)for(b=a;(b+=a)<50001;)f[a]||f[b]++;for(;scanf("%d",&n),n;printf("%d\n",b))for(b=0,a=1;a++<n/2;)f[a]+f[n-a]||b++;exit(0);}

Measured memory_bytes: 600
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
for i in range(n):
    a[i+1] = (a[i+1]+a[i])%m

from collections import defaultdict
pairs = defaultdict(int)

for x in a:
    pairs[x] += 1

ans = 0
for v in pairs.values():
    ans += v*(v-1)//2

print(ans)


Measured memory_bytes: 14408
package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mp := map[int]int{}
	for _, v := range A {
		mp[v]++
	}

	mx := 0
	mx2 := 0
	mp4 := map[int]int{}
	for k, v := range mp {
		if v >= 4 {
			mp4[k]++
		}
		if v >= 2 {
			if mx < k {
				mx2 = mx
				mx = k
			} else if mx2 < k {
				mx2 = k
			}
		}
	}
	if mp4[mx] > 0 {
		fmt.Println(mx * mx)
	} else {
		fmt.Println(mx * mx2)
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 8960