akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;
typedef pair<int,int>           PI;
typedef pair<ll,ll>             PL;
typedef vector<PI>               vip; 
typedef vector<int>             vi;
typedef vector<vi>              vvi;
typedef vector<ll>              vl;
typedef vector<vl>              vvl;
    
bool graph[8][8];

int dfs(int v, int n, bool visited[8]){
    bool all_visited = true;
    for(int i = 0; i < n; i++){
        if(visited[i] == false)
            all_visited = false;
    }

    if(all_visited){
        return 1;
    }

    int ret = 0;
    for(int i = 0; i < n; i++){
        if(graph[v][i]==false) continue;
        if(visited[i]) continue;
        visited[i]=true;
        ret+=dfs(i,n,visited);
        visited[i]=false;
    }

    return ret;
}






int main (){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    REP(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        graph[a][b] = 1;
        graph[b][a] = 1;
    }
    bool visited[8];
    REP(i,n){
        visited[i] = false;
    }

    visited[0] = true;
    cout << dfs(0,n,visited) << endl;




    return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    aList = [list(input().split()) for i in range(N)]
    X = input()

    sleep = False
    ans = 0

    for item in aList:
        if sleep == True:
            ans += int(item[1])
        if X == item[0]:
            sleep = True

    print(ans)
    
if __name__ == '__main__':
    solve()


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

void dfs(int v, int &t, const V<V<int>> &g, V<P> &time) {

    t++;
    time[v].fi = t;
    for(int nv : g[v]) {
        if(time[nv].fi) continue;
        dfs(nv, t, g, time);
    }
    t++;
    time[v].se = t;
}

int main(){

    int n;
    cin >> n;
    V<V<int>> g(n);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        a--;
        rep(j,k) {
            int b;
            cin >> b;
            b--;
            g[a].push_back(b);
        }
    }
    V<P> time(n);
    int t = 0;
    rep(i,n) {
        if(time[i].fi) continue;
        dfs(i, t, g, time);
    }
    rep(i,n) {
        printf("%d %d %d\n", i+1, time[i].fi, time[i].se);
    }
}


Measured memory_bytes: 3288
use proconio::input;
use proconio::marker::Usize1;
use superslice::*;

fn dfs(
    ls: &mut Vec<usize>,
    lis: &mut Vec<u64>,
    es: &Vec<Vec<usize>>,
    ais: &Vec<u64>,
    u: usize,
    p: usize,
) {
    let a = ais[u];
    let b = if *(lis.last().unwrap_or(&0)) < a {
        lis.push(a);
        None
    } else {
        let i = lis[..].lower_bound(&a);
        let x = lis[i];
        lis[i] = a;
        Some((i, x))
    };
    ls[u] = lis.len();
    for &v in es[u].iter() {
        if v == p {
            continue;
        }
        dfs(ls, lis, es, ais, v, u);
    }
    match b {
        None => {
            lis.pop();
        }
        Some((i, x)) => lis[i] = x,
    }
}

fn main() {
    input! {
        n: usize,
        ais: [u64; n],
        uvs: [(Usize1, Usize1); n - 1],
    };

    let mut es = vec![vec![]; n];
    for (u, v) in uvs {
        es[u].push(v);
        es[v].push(u);
    }

    let mut ls = vec![0_usize; n];
    dfs(&mut ls, &mut vec![], &es, &ais, 0, 0);

    for l in ls {
        println!("{}", l);
    }
}


Measured memory_bytes: 39288
n = int(input())
s = ''
for i in range(1, n+1):
    if i % 3 == 0:
        s += ' ' + str(i)
        continue
    x = i
    while x:
        if x % 10 == 3:
            s += ' ' + str(i)
            break
        x //= 10
s.rstrip()
print(s)


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int bills = n/1000;
    bills++;
    if(n%1000 == 0){
        cout << "0\n";
        return 0;
    }
    int bal = bills*1000 - n;
    cout << bal << "\n";
    return 0;
}

Measured memory_bytes: 3584
n = int(input())

A = [[]]
for _ in range(n):
    A += [[int(x) for x in input().split()]]

B = [[0, 0, 0] for _ in range(n + 1)]

for i in range(1, n + 1):
    for j in range(3):
        B[i][j] = A[i][j] + max([B[i - 1][(j + m) % 3] for m in [1, 2]])

print(max(B[n]))


Measured memory_bytes: 44084
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;



int main()
{
	lld n;
	cin >> n;

	lld res[1001] = {0};


	for(lld i = 2; i <= n; i++)
	{
		lld x = i;
		for(lld j = 2; j*j <= x; j++)
		{
			while(x%j == 0)
			{
				res[j]++;
				x /= j;
			}
		}
		if (x != 1)
		{
			res[x]++;
		}
	}

	lld ans = 1;
	for(int i = 1; i <= n; i++)
	{
		ans *= (res[i] + 1) ;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll r;
    cin >> r;
    cout << r * r << endl;
}



Measured memory_bytes: 888
// https://twitter.com/chokudai/status/1294961358119739392
// https://atcoder.jp/contests/abc175/submissions/15987037

use proconio::input;

fn main() {
    input!(x: i64, k: i64, d: i64);
    println!("{}", solve(x, k, d))
}

fn solve(mut x: i64, mut k: i64, d: i64) -> i64 {
    x = x.abs();
    if x >= k.saturating_mul(d) {
        x - k * d
    } else {
        k -= x / d;
        x %= d;
        if k % 2 == 1 {
            d - x
        } else {
            x
        }
    }
}

fn solve_simply(mut x: i64, k: i64, d: i64) -> i64 {
    for _ in 0..k {
        if (x - d).abs() < (x + d).abs() {
            x -= d
        } else {
            x += d
        }
    }
    x.abs()
}

#[test]
fn test() {
    use rand::prelude::*;
    let mut rng = thread_rng();
    loop {
        let x = rng.gen_range(-1e15 as i64, 1e15 as i64 + 1);
        let k = rng.gen_range(1, 1e5 as i64 + 1);
        let d = rng.gen_range(1, 1e15 as i64 + 1);
        println!("checking input : {} {} {}", x, k, d);
        assert_eq!(solve(x, k, d), solve_simply(x, k, d));
    }
}


Measured memory_bytes: 2144
using System;

namespace abc148
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var st = Console.ReadLine().Split();
            var s = st[0];
            var t = st[1];

            for (int i = 0; i < n; i++)
            {
                Console.Write(s[i]);
                Console.Write(t[i]);
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

using namespace std;

typedef long long lint;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

lint get_negative_kth(vector<lint>& pos, vector<lint>& neg, lint K)
{
    auto count = [&pos, &neg](lint x) {
        lint total = 0;
        for (lint p : pos)
            total += upper_bound(ALL(neg), x / p) - BEGIN(neg);
        return total;
    };

    lint lo = 1, hi = pos.back() * 1LL * neg.back();
    while (hi - lo > 1) {
        lint mid = (lo + hi) / 2;
        if (count(mid) >= K)
            hi = mid;
        else lo = mid + 1;
    }

    if (lo != hi && count(lo) < K)
        lo = hi;
    return -lo;
};

lint get_positive_kth(vector<lint>& pos, vector<lint>& neg, lint K)
{
    auto count = [&neg, &pos](lint x) {
        lint total = 0;
        for (int i = 0;i < neg.size(); i++) {
            lint n = neg[i];
            int j = upper_bound(BEGIN(neg), BEGIN(neg) + i, x / n) - BEGIN(neg);
            total += min(j, i);
        }
        for (int i = 0;i < pos.size(); i++) {
            lint n = pos[i];
            int j = upper_bound(BEGIN(pos), BEGIN(pos) + i, x / n) - BEGIN(pos);
            total += min(j, i);
        }

        return total;
    };

    lint lo = 1, hi = 1LL << 62;
    while (hi - lo > 1) {
        lint mid = lo + (hi - lo) / 2;
        if (count(mid) >= K)
            hi = mid;
        else lo = mid + 1;
    }

    if (lo != hi && count(lo) < K)
        lo = hi;
    return lo;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    lint K;
    cin >> N >> K;
    vector<lint> neg, pos;
    int zeros = 0;
    for (int i = 0;i < N; i++) {
        int t;
        cin >> t;
        if (t < 0)
            neg.push_back(-t);
        else if (t > 0)
            pos.push_back(t);
        else zeros++;
    }

    sort(ALL(pos));
    sort(ALL(neg));

    lint negpairs = neg.size() * 1LL * pos.size();
    lint zeropairs = neg.size() * 1LL * zeros + pos.size() * 1LL * zeros;
    zeropairs += zeros * 1LL * (zeros - 1) / 2;
    lint ret = 0;
    if (negpairs >= K) {
        ret = get_negative_kth(pos, neg, negpairs + 1 - K);
    } else if (negpairs + zeropairs >= K)
        ret = 0;
    else {
        K -= negpairs + zeropairs;
        ret = get_positive_kth(pos, neg, K);
    }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 2420
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: i64, k: i64,
    }
    let mut n = n;
    let mut c = 0;
    while n > 0 {
        n /= k;
        c += 1;
    }
    puts!("{}\n", c);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), c;
    int sum = 0;
    rep(i, 0, n){
        cin >> a[i];
        sum += a[i];
        if(a[i] <= 0){
            c.push_back(-a[i]);
            sum += 2 * (-a[i]);
        }
    }
    if(c.size() % 2){
        int MIN = INF;
        rep(i, 0, n) MIN = min(MIN, abs(a[i]));
        // cout << MIN << endl;
        sum -= 2 * MIN;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,q;
int main(void) {
    cin >> n >> q;
    string s;
    cin >> s;
    vector<pair<int,int> > lr;
    rep(i,q){
        int t1,t2;
        cin >> t1 >> t2;
        lr.push_back(make_pair(t1,t2));
    }
    vector<int> cnts;
    int cnt=0;
    cnts.push_back(0);
    rep(i,n){
        if(i==0){cnts.push_back(0);}
        else{
            if(s.substr(i-1,2)=="AC"){
                cnt+=1;
            }
            cnts.push_back(cnt);
        }
    }
    rep(i,q){
        cout << cnts[lr[i].second]-cnts[lr[i].first] << endl;
    }
    return 0;
}


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;int a,b,c,d,e,f,s1,s2,s3,s,p,i;main(){while(1){s=0;cin>>a>>b>>c>>d>>e>>f;s1=a+d;s2=b+e;s3=c+f;if(s1+s2+s3==0){break;}p=min(s1,min(s2,s3));for(i=max(0,p-9);i<=p;i++){s=max(s,i+(s1-i)/3+(s2-i)/3+(s3-i)/3);}cout<<s<<endl;}}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

bool lessPair(pair<int, int> a, pair<int, int> b) {
	
	if (a.second != b.second) {
		return a.second < b.second;
	}

	return a.first < b.first;
}




int main() {

	int n;
	cin >> n;

	vector<pair<int, int>> task(n);


	int wk1, wk2;


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

		cin >> wk1 >> wk2;


		//(タスク所要時間,タスク締め切り）
		task[i] = make_pair(wk1, wk2);
	}

	sort(task.begin(), task.end(), lessPair);

	int time = 0;
	bool canDo = true;


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

		time += task[i].first;

		if (time > task[i].second) {
			canDo = false;
			break;
		}
	}

	if (canDo) {
		
		cout << "Yes" << endl;


	}
	else {

		cout << "No" << endl;


	}


	


	return 0;




}



Measured memory_bytes: 1792
#include<stdio.h>
using namespace std;
typedef long long LL;
LL lucas[100];
int main()
{
	lucas[0] = 2;
	lucas[1] = 1;
	for(int i = 2; i <= 86; i++)
		lucas[i] = lucas[i-1]+lucas[i-2];
	int N;
	scanf("%d",&N);
	printf("%lld",lucas[N]);
	return 0;
}

Measured memory_bytes: 128
n, a, b = map(int, input().split())

mod = 10 ** 9 + 7

def frac_rev(n, r):
  x = 1
  for i in range(n, n-r, -1):
    x = x * i % mod
  return x

def frac(n):
  x = 1
  for i in range(1, n+1):
    x = x * i % mod
  return x

print(( pow(2, n, mod) - 1 - frac_rev(n, a) * pow(frac(a), mod-2, mod) % mod - frac_rev(n, b) * pow(frac(b), mod-2, mod) % mod) % mod)

Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <queue>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr long long inf = (1ll << 60);
constexpr int mx_money = 5000;
struct edge { int to, money, time; };

int main() {
  int N, M, S;
  std::cin >> N >> M >> S;
  std::vector<std::vector<edge>> graph(N);
  for (int i: range(0, M)) {
    int u, v, a, b;
    std::cin >> u >> v >> a >> b;
    --u; --v;
    graph[u].push_back(edge{ v, a, b });
    graph[v].push_back(edge{ u, a, b });
  }
  std::vector<int> get(N), need(N);
  for (int i: range(0, N)) {
    std::cin >> get[i] >> need[i];
  }
  std::vector<std::array<long long, mx_money + 1>> dist(N);
  for (auto &v: dist) {
    v.fill(inf);
  }
  using state = std::tuple<long long, int, int>;
  std::priority_queue<state, std::vector<state>, std::greater<state>> que;
  dist[0][std::min(mx_money, S)] = 0;
  que.emplace(dist[0][std::min(mx_money, S)], 0, std::min(mx_money, S));
  while (!que.empty()) {
    auto [d, v, m] = que.top();

    que.pop();
    if (d > dist[v][m]) {
      continue;
    }
    for (auto e: graph[v]) {
      if (m >= e.money && chmin(dist[e.to][m - e.money], dist[v][m] + e.time)) {
        que.emplace(dist[e.to][m - e.money], e.to, m - e.money);
      }
    }
    if (chmin(dist[v][std::min(mx_money, m + get[v])], dist[v][m] + need[v])) {
      que.emplace(dist[v][std::min(mx_money, m + get[v])], v, std::min(mx_money, m + get[v]));
    }
  }
  for (int i: range(1, N)) {
    long long ans = *std::min_element(dist[i].cbegin(), dist[i].cend());
    std::cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 9384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int b=0;
	char a[10000];
	gets(a);
	for (int i=0;i<strlen(a);i++)
		if (a[i]=='9')
		b=1;
	if (b==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
	char ch; int sign = 1;
	while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
	n = ch - '0';
	while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
	n *= sign;
}
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int MOD = INF;
const int N = 1222222;
int n;
ll fac[N], inv[N];

ll C(ll n, ll m){return fac[n] * inv[m] % MOD * inv[n-m] % MOD;}

int main(){
	read(n);
	fac[0] = inv[0] = inv[1] = 1; 
	rep(i, 1, N - 1) fac[i] = fac[i-1] * i % MOD;
	rep(i, 2, N - 1) inv[i] = (MOD - MOD / i * inv[MOD%i] % MOD) % MOD;
	rep(i, 2, N - 1) inv[i] = inv[i-1] * inv[i] % MOD;
	ll ans = 0;
	rep(i, n / 2, n - 1){
		ll t = C(i - 1, n - 1 - i) * fac[i] % MOD * fac[n-1-i] % MOD;
		(ans += t) %= MOD;
	}
	cout << (fac[n-1] * n % MOD - ans + MOD) % MOD << endl;
	return 0;
}

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

int main() {
    vector<int> v;
    for(int i = 0; i < 10; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    string str;
    for(int i = 9; i >6; i--) {
        str += to_string(v[i]);
        str += "\n";
    }
    str.pop_back();
    cout << str << endl;
}

Measured memory_bytes: 3244
#include <stdio.h>
int main(){
	int n,x;
	scanf("%d %d",&n,&x);
	int m[n];
	int ans=0;
	int min=1000;
	for(int i=0;i<n;i++){
		scanf("%d",&m[i]);
		x	-=m[i];
		if( min > m[i]){
			min = m[i];
		}
	}
	ans += n + (x/min);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
 
// #define fisier 1
 
using namespace std;
 
typedef long long ll;
 
const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;
 
int n, q;
int v[500002];
int aib[500002];
void add(int nod, int val)
{
	for(; nod <= n; nod += (nod & (-nod)))
		aib[nod] += val;
}
int query(int nod)
{
	int ans = 0;
	for(; nod; nod -= (nod & (-nod)))
		ans += aib[nod];
	return ans;
}
struct qu
{
	int L, R, org;
};
qu vq[500002];
bool cmp(qu a, qu b)
{
	return a.R < b.R;
}
int quans[500002];
int lst[500002];
int main()
{
	#ifdef fisier
		ifstream cin("input.in");
		ofstream cout("output.out");
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> q;
	for(int i = 1; i <= n; ++i)
		cin >> v[i];
	for(int i = 1; i <= q; ++i)
	{
		cin >> vq[i].L >> vq[i].R;
		vq[i].org = i;
	}
	sort(vq + 1, vq + q + 1, cmp);
	int qn = 1;
	for(int i = 1; i <= n; ++i)
	{
		if(lst[v[i]] != 0)
		{
			add(lst[v[i]], -1);
		}
		add(i, 1);
		lst[v[i]] = i;
		while(qn <= q && vq[qn].R == i)
		{
			quans[vq[qn].org] = query(vq[qn].R) - query(vq[qn].L - 1);
			++qn;
		}
	}
	for(int i = 1; i <= q; ++i)
		cout << quans[i] << '\n';
	return 0;
}


Measured memory_bytes: 17440
main = do
  _ <- getLine
  s <- getLine
  let ans = compute s
  putStrLn ans

type Animal = Char -- 'S' or 'W'
type OX     = Char -- 'o' or 'x'

next :: (Animal, Animal) -> OX -> (Animal, Animal)
next ( a, 'S') 'o' = ('S', a)
next ( a, 'W') 'x' = ('W', a)
next ('S', b )  _  = (b, 'W')
next ('W', b )  _  = (b, 'S')

compute s = if null answers then "-1" else head answers
  where
    answers =
      [ map fst (tail seq)
      | i <- [('S','S'),('S','W'),('W','S'),('W','W')]
      , let seq = scanl next i s
      , head seq == last seq
      ]


Measured memory_bytes: 28028
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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



















int main(){
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S;
	rep(i, 0, 3)
	{
		cin >> S;
		cout << S[0];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;

char S[100010];
int p[100010];

void solve(){
	int n;
	scanf("%d%s", &n, S);
	rep(a, 2)rep(b, 2){
		p[0] = a;
		p[1] = b;
		int ok = 1;
		for(int i=2;i<=n+1;i++){
			int t = (i+n-1) % n;
			int t2 = (i+n-2) % n;
			int x = (S[t] == 'o') ^ p[t] ^ p[t2];
			if(i < n)p[i] = x;
			else if(p[i%n] != x)ok = 0;
		}
		if(ok){
			for(int i=0;i<n;i++)printf("%c", p[i] ? 'S' : 'W'); puts("");
			return;
		}
	}
	puts("-1");
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;cin>>s;
    if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
typedef long long int ll;


int main() {
	vector<string> sv(3);
	loop(i, 3) cin >> sv[i];
	loop(i, 3) cout << sv[i][i];
	cout << endl;
}

Measured memory_bytes: 384
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 
#define int ll
using namespace std;

const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const long double eps = 1e-9 ;

using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

const int LG = 18;
int d[N] , up[LG][N] , sub[N] , n; 
vector<int> g[N];

void dfs(int u , int p = 0){
    if(p != 0) d[u] = d[p] + 1; 
    up[0][u] = p; 
    sub[u]++ ;
    rep(i , LG - 1) up[i + 1][u] = up[i][up[i][u]];
    trav(v , g[u]) if(v != p){
        dfs(v , u);
        sub[u] += sub[v];
    }
} 

int lca(int u , int v){
    if(d[u] > d[v]) swap(u , v);
    int k = d[v] - d[u] , U = u , V = v;
    repD(i , LG - 1, 0) if(k >> i & 1){
        v = up[i][v] ;
    }
    if(u == v) return u ;
    repD(i , LG - 1 , 0){
        if(up[i][u] != up[i][v]){
            u = up[i][u];
            v = up[i][v];
        }
    }
    return up[0][u];
}

int go_up(int u, int h){
    repD(i , LG - 1 , 0) if(h >> i & 1) u = up[i][u];
    return u ;
}

pii get(int u , int v){
    int l = lca(u , v);
    int t = d[l] * 2LL - d[u] - d[v];  
    t *= -1;
    t = (t - 1)/2 ;
    // cout << t << '\n';
    if(d[u] <= d[v]){
        // first will get
        v = go_up(v , t);
        // cout << u << ' ' << v << '\n';
        return mp(n - sub[v] , sub[v]);
    }else{
        u = go_up(u , t);
        // cout << u << ' ' << v << '\n';
        return mp(sub[u] , n - sub[u]);
    }
}

void solve()
{
    cin >> n ;
    rep(i , n - 1){
        int x , y;
        cin >> x >> y ;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    auto p = get(1 , n);
    // cout << p.ff << ' ' << p.ss << '\n';
    cout << (p.ff > p.ss ? "Fennec" : "Snuke");
}
     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


Measured memory_bytes: 61312
#include <iostream>

using namespace std;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int res = 0;
  for (int i = 0; i <= A; ++i) {
    if (500 * i + 100 * B + 50 * C < X) continue;
    if (X < 500 * i) break;;
    for (int j = 0; j <= B; ++j) {
      if (500 * i + 100 * j + 50 * C < X) continue;
      if (X < 500 * i + 100 * j) break;;
      for (int k = 0; k <= C; ++k) {
        if (X <= 500 * i + 100 * j + 50 * k) {
          res += (500 * i + 100 * j + 50 * k == X);
          break;
        }
      }
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

vector<pair<ll,ll> > to[100005];
vector<ll> dp(100005);
// Kからの最短距離を各頂点について求めて、最後に足し算すれば良い。

void dfs(ll v, ll parent, ll distance){
    dp.at(v) = distance;
    for(pair<ll, ll> child: to[v]){
        if(child.first == parent) continue;
        dfs(child.first, v, distance + child.second);
    }
}

int main(){
    ll N, Q, K;
    cin >> N;
    rep(i, N-1) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--;
        B--;
        to[A].emplace_back(make_pair(B, C));
        to[B].emplace_back(make_pair(A, C));
    }
    cin >> Q >> K;
    dfs(K-1, -1,0);
    rep(i, Q) {
        ll x, y;
        cin >> x >> y;
        cout << dp.at(x-1) + dp.at(y-1) << endl;
    }
}

Measured memory_bytes: 15540
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll W,n;
vector<ll>val,wt;
vector<vector<ll> >k(0,vector<ll>(0,0));
ll knapsack(){
    k.assign(n+1,vector<ll>(W+1,0));
    for(ll i=1;i<=n;i++)
        for(ll w=1;w<=W;w++)
            if(wt[i-1]<=w)
                k[i][w]=max(val[i-1]+k[i-1][w-wt[i-1]],k[i-1][w]);
            else
                k[i][w]=k[i-1][w];


    return k[n][W];
}
int main(){

    while(cin>>n>>W){
        val.assign(n,0);
        wt.assign(n,0);

        for(ll i=0;i<n;i++)
            cin>>wt[i]>>val[i];

        ll res=knapsack();
        cout<<res<<endl;
    }
    return 0;
}


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

int main() {
  for(int n, r; cin >> n >> r && (n|r); ){
    deque<int> deq;
    for(int i = 0; i < n; ++i) deq.push_front(i+1);
    for(int i = 0; i < r; ++i) {
      int p, c;
      cin >> p >> c;
      --p;
      deque<int> tmp(deq.begin() + p, deq.begin() + (p+c));
      deq.erase(deq.begin() + p, deq.begin() + (p+c));
      for(int j = (int)tmp.size()-1; j >= 0; --j) deq.push_front(tmp[j]);
    }
    cout << deq.front() << endl;
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    if(n %2==0) cout << n /2;
    else cout << n/2 + 1;


    
}

Measured memory_bytes: 256
N,K=list(map(int,input().split()))
x = list(map(int,input().split()))

left = 0
right = left+(K-1)
time = 10**9
while right < N:
    d = x[right]-x[left]
    time = min(time, d+abs(x[right]), d+abs(x[left]))
    left += 1
    right += 1
print(time)


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    
    if ((a + b) == 15) {
        cout << "+" << endl;
    }
    else if ((a * b) == 15) {
        cout << "*" << endl;
    }
    else {
        cout << "x" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n;
int a[N*2];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+2*n+1);;
	int ans=0;
	for(int i=1;i<=2*n;i+=2)
	{
		ans+=a[i];
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
vector<pair<ll, ll>> d;
 
int main(int, char**)
{
	unsigned int n;
	ll t = 0, s = 0;
	cin >> n;
	d.resize(n);
 
	for (unsigned int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		d[i].first = a + b;
		d[i].second = a;
	}
 
	sort(d.begin(), d.end(), greater<>());
 
	for (unsigned int i = 0; i < n; i++) {
		if (i % 2 == 0) t += d[i].second;
		else s += d[i].first - d[i].second;
	}
 
    cout << t - s << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int x, y, z, a, b, c;
    cin>>x>>y>>z;

    a=x+y;
    b=y+z;
    c=x+z;
    if(a<=b && a<=c)
    {
        cout<<a;
    }
    else if(b<=a && b<=c)
    {
        cout<<b;
    }
    else if(c<=a && c<=b)
    {
        cout<<c;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
a2n = lambda c: ord(c) - ord("A") + 1
n2a = lambda c: chr(c + 64)
r = []
for c in s:
    nc = a2n(c) + n
    if nc > 26:
        nc -= 26
    r.append(n2a(nc))
print("".join(r))


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

int main() {
  int N; cin >> N;
  string W[N];
  for(int i = 0; i < N; i++) cin >> W[i];

  bool flag = false;
  for(int i = 0; i < N-1; i++) {
    if(flag) break;
    if(W[i].back() != W[i+1].front()) flag = true;
  }
  if(!flag) {
    sort(W, W+N);
    for(int i = 0; i < N-1; i++) {
      if(W[i] == W[i+1]) {
        flag = true;
        break;
      }
    }
  }

  cout << (flag ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define r1(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long Long
#define IT itreator
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",student)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
int res[505][505];
void dfs(int start,int to,int index)
{
    if(to-start+1<=1) return;
    for(int i=start;i<to;i++)
        for(int j=i+1;j<=to;j++)
    {
        res[i][j]=index;
    }
        int mid=(start+to)>>1;
        dfs(start,mid,index+1),dfs(mid+1,to,index+1);
    }
    int main()
    {
        cin>>n;
        dfs(1,n,1);
        for(int i=1;i<n;i++)
            for(int j=i+1;j<=n;j++)
            cout<<res[i][j]<<" ";

}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0; i<S.size()-1; i++)
    {
        if(S.at(i+1)==S.at(i))
        {
            N--;
        }
    }
    cout << N <<endl;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	for(int i = 0;i<n/2;i++)
	{
		int b = a[i];
		a[i] = a[n-1-i];
		a[n-1-i] = b;
	}
	for(int i = 0;i<n;i++)
	{
		if(i)cout<<' ';
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<cmath>

using namespace std;


#define N 3
#define N2 9
//--------------------------------------- 
struct P{
    int f[N2];
    int space;
    string path;

     
    bool operator < (const P &p) const{
        for(int i = 0; i < N2; i++){
            if(f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};

//-------------------------------------------- 
static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};
 
//--------------------------------------------
bool isTarget(P p){
    for(int i = 0; i < N2; i++)
        if(p.f[i] != (i + 1)) return false;
    return true;
}
//--------------------------------------------
string bfs(P s){
    queue<P> Q;
    map<P, bool> V;
    P u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;
     
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        if(isTarget(u)) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for(int r = 0; r < 4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if(!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}
//-----------------------------
int main(){
    P in;
    for(int i = 0; i < N2; i++){
        cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
     
    return 0;
}





Measured memory_bytes: 30604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
//int ar[100001];

int main() {
	io;
	int n;
	cin>>n;
	int a;
	bool flag = false;
	while(n) {
		a = n%10;
		if(a == 7)
			{
				flag = 1;
				break;
			}
		n /= 10;
	}
	if(flag)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3652
fun main() {
    println(solve())
}

val solve: () -> Any = {
    (1L..readLong()).filter { it % 3L != 0L && it % 5L != 0L }.sum()
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()

Measured memory_bytes: 58944
package main

import (
	"fmt"
)

func main() {
	var n int64
	fmt.Scan(&n)

	fs := factorization(n)

	var cnt int
	for _, f := range fs {
		x := f.q
		b := int64(1)
		for b <= x {
			x -= b
			b++
			cnt++
		}
	}
	fmt.Println(cnt)
}

// Pow の定義
type Pow struct {
	p, q int64
}

// Pow の生成
func newPow(p, q int64) *Pow {
	a := new(Pow)
	a.p, a.q = p, q
	return a
}

// Stringer の定義
func (p *Pow) String() string {
	return fmt.Sprintf("(%d, %d)", p.p, p.q)
}

// m で割り切れる回数を求める
func factorSub(n, m int64) (int64, int64) {
	i := int64(0)
	for ; n%m == 0; n /= m {
		i++
	}
	return i, n
}

// 素因数分解
func factorization(n int64) []*Pow {
	a := make([]*Pow, 0)
	c, m := factorSub(n, 2)
	if c > 0 {
		a = append(a, newPow(2, c))
	}
	for i := int64(3); m >= i*i; i += 2 {
		c, m = factorSub(m, i)
		if c > 0 {
			a = append(a, newPow(i, c))
		}
	}
	if m > 1 {
		a = append(a, newPow(m, 1))
	}
	return a
}


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

int main(void){
    int n;
    cin >> n;
    
    int min = 1000000000, max = 1, input;
    int i;
    for(i = 1; i <= n; i++){
        cin >> input;
        if(input < min){
            min = input;
        }
        if(input > max){
            max = input;
        }
    }
    
    cout << max - min << endl;
    
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    int x = 0, ans = 0;
    for (auto s : S) {
       x += (s == 'I' ? 1 : -1); 
       ans = max(ans, x);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import fractions

n = int(input())
a = [int(input()) for i in range(n)]

if len(a) == 1:
    print(a[0])
    exit()

ans = a[0] * a[1] // fractions.gcd(a[0],a[1])

for i in range(1,n-1):
    ans = ans * a[i+1] // fractions.gcd(ans,a[i+1])
    
print(ans)

Measured memory_bytes: 5048
from itertools import accumulate

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

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

MOD = int(1e9+7)

dp = [0] * (K+1)
dp[0] = 1

for n in range(N):

    sumlist = [0]
    sumlist += dp[:]
    sumlist = list(accumulate(sumlist))

    ndp = [0] * (K+1)
    for k in range(K+1):
        ndp[k] = sumlist[k+1] - sumlist[max(0, k - A[n])] 
        ndp[k] %= MOD
    dp = ndp
                # dp[k] ~ dp[k-A[n]] made
print(dp[K]%MOD)



Measured memory_bytes: 121024
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int n;
ll a[100001],b[100001];

bool f(int x){
    for(int i=x+1;i<=n;i++){
        if(a[i]>b[i-1]*2)return false;
    }
    return true;
}

int main(void){
    cin>>n;
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a, a+n+1);
    b[0]=0;
    for(int i=1;i<=n;i++){
        b[i]=b[i-1]+a[i];
    }
    int l=0,r=n;
    while(l+1<r){
        int m=(l+r)/2;
        if(f(m)){
            r=m;
        }else{
            l=m;
        }
    }
    cout<<n-l<<endl;
}


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

int d,n;

void input()
{
    std::cin>>d>>n;
}

int wareru(int i)
{
    int res = 0;
    while(i % 100 == 0){
        i /= 100;
        res++;
    } 
    return res;
}


int main()
{
    input();
    int cnt = 0,val = 0;
    while(cnt <n)
    {
        val++;
        if(wareru(val)==d)cnt++;
    }
    std::cout<<val<<std::endl;
}

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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;



int main() {
const ll INF = 1001001001;
const ld PI = 3.14159265358979323846;
int N;
bool judge=false;
cin>>N;
rep3(i,9){
    rep4(j,i,9){
        if(i*j==N){
            judge=true;
        }
    }
}
if(judge){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}
return 0;
}



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

int main(){
    int N;
    int s;
    int fx = 0;//整数の位の和
    int n;
    int m;
    cin >> N;
    n = N;//入力された整数値を保持//
    m = N;
    while(!(N == 0)){
        s++;
        N = N/10;
    }
    for(int i=0;i<s;i++){
        fx = fx + n%10;
        n = n/10;
    }
    if(m%fx == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	int a,b;
	cin>>a>>b;
	if(a<1||a>9||b<1||b>9)
		cout<<-1;
	else
		cout<<a*b;
	return 0;
}


Measured memory_bytes: 256