akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d,ans=0,b;
	cin >> n >> d;
	int a[n][d];
	for(int i=0;i<n;i++)
		for(int j=0;j<d;j++)
			cin >> a[i][j];
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			b=0;
			for(int k=0;k<d;k++)
			{
				b += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			for(int k=0;k*k <= b;k++)
				if(k*k == b)
					ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    cout << (x - z) / (y + z) << endl;

    return 0;
}

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

#define int long long

vector<int> tmp[200010];
pair<int, int> graph[200010][2];
int visited2[200010] = {};
int a[200010];
int visited[200010][2] = {};

signed main(){
    int n, k;
    cin >> n >> k;

    for(int i = 0;i < n;i++){
        cin >> a[i];
        tmp[a[i]].push_back(i);
        graph[i][1] = make_pair((i+1)%n, i == n-1 ? 1 : 0);
    }

    for(int i = 0;i < n;i++){
        int next = upper_bound(tmp[a[i]].begin(), tmp[a[i]].end(), i) - tmp[a[i]].begin();
        if(next == tmp[a[i]].size()){
            graph[i][0] = make_pair(tmp[a[i]][0], 1);
        }else{
            graph[i][0] = make_pair(tmp[a[i]][next], 0);
        }
    }


    int v = 0;
    int og = 0;
    int cost = 0;
    while(1){
        if(visited[v][og] != 0){
            break;
        }

        visited[v][og] = 1;
        int nv = graph[v][og].first;
        cost += graph[v][og].second;
        v = nv;
        og = (og+1) % 2;
    }


    k = k - (k/cost)*cost;

    deque<int> que;


    while(k > 0){

        k -= graph[v][og].second;

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

                if(visited2[a[i]] == 0){
                    que.push_back(a[i]);
                    visited2[a[i]] = 1;
                }else{

                    while(que.back() != a[i]){
                        visited2[que.back()] = 0;
                        que.pop_back();
                    }

                    que.pop_back();
                    visited2[a[i]] = 0;
                }


            }

            break;
        }

        v = graph[v][og].first;
        og = (og+1) % 2;
    }


    while(!que.empty()){
        cout << que.front();
        que.pop_front();
        if(que.empty()){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 26624
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;
struct edge{
	int from;
	int to;
};
typedef multimap <int, edge, less<int> > mme;

int addedge(vvi &graph, int y, int x, int val=1){
	graph[y][x] = val;
	return val;
}

int make_graph(vvi &graph, vi &stamp){
	int n=graph.size(), val;

	for (int j=0; j<n; j++){
		for (int i=0; i<n; i++){
			cin>>val;
			addedge(graph, i, j, val);
		}
		stamp[j] = 0;
	}
	return 0;
}

int Minimum_Spanning_Tree(vvi &graph, vi &stamp){

	mme edges;
	int n = graph.size(), p1, p2, p3, total=0;
	p1=0;
	stamp[p1] = 1;

	while (p1!=-1){
		for (int p2=0; p2<n; p2++){
			int *tmp=&graph[p1][p2];
			if (*tmp!=-1 && stamp[p2]==0){
				edge e;
				e.from = p1;
				e.to = p2;
				edges.insert(pair <int, edge> (*tmp, e));
			}
		}
		p1=-1;
		while (! edges.empty()){
			mme::iterator const it = edges.begin();
			if (stamp[it->second.from]==1 && stamp[it->second.to]==0){
				p1 = it->second.to;
				stamp[p1]=1;
				total+=it->first;
				edges.erase(it);
				break;
			}
			edges.erase(it);
		}
	}
	return total;
}

int resultout(vvi &graph){
	for (int i=0; i<int(graph.size()); i++){
		for (int j=0; j<int(graph.size()); j++){
		cout<<graph[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

int main(void){

	int n, row;
	cin>>n;
	vvi G(n, vi(n));
	vi stamp(n);

	make_graph(G, stamp);

	cout<<Minimum_Spanning_Tree(G, stamp)<<endl;

	return 0;
} 

Measured memory_bytes: 1472
// https://atcoder.jp/contests/arc098/tasks/arc098_c

#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <set>
 
using namespace std;

using INT = long long int;
using VEC = std::vector<INT>;
const INT INF = INT(1) << 60;

#define FOR(i, N) for( INT i = 0; i < N; i++ )
#define RANGE(v) begin(v), end(v)

int main(void){
    INT N, K, Q;

    cin >> N >> K >> Q;
    VEC ax(N);
    
    FOR(i, N) cin >> ax[i];

    INT ans = INF;

    for( auto m : ax ){
        VEC tmp, ret;
        for( auto a : ax ){
            if ( a < m ){
                auto s = tmp.size();
                if( s >= K ) {
                    std::sort( RANGE(tmp) );
                    for( INT i = 0; i < Q && i < s-K+1; i++ ){
                        ret.push_back(tmp[i]);
                    }
                }
                else { /* NOP */ }
                tmp.clear();
            } else {
                tmp.push_back(a);
            }
        }

        // last
        auto s = tmp.size();
        if( s >= K ) {
            std::sort( RANGE(tmp) );
            for( INT i = 0; i < Q && i < s-K+1; i++ ){
                ret.push_back(tmp[i]);
            }
        }

        if( ret.size() >= Q ){
            std::sort( RANGE(ret) );
            ans = std::min( ans, (ret[Q-1] - ret[0]) );
        }
    }

    cout << ans << endl;

}



Measured memory_bytes: 384
input = []
while (n = gets.to_i) != 0 do
  input = gets.split.map(&:to_i)
end

count = 0
for flag in 0..input.size-1 do
  for i in -input.size + 1..-flag do
    j = -i
    if input[j] < input[j-1] && j != 0
      tmp = input[j]
      input[j] = input[j-1]
      input[j-1] =tmp
      count += 1
    end
  end
end
puts input*" "
puts count


Measured memory_bytes: 6876
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int a, b; cin >> a >> b;

  if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;
    return 0;
  }

  if (a < 0 && b < 0) {
    int cnt = b-a+1;
    if (cnt%2 != 0) {
      cout << "Negative" << endl;
      return 0;
    }
  }

  cout << "Positive" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int arr[5];
  for(int i=0;i<5;i++)cin>>arr[i];
  for(int i=0;i<5;i++){
    if(arr[i]==0){
      cout<<i+1<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll n, m;
    map<string, ll> mp;
    cin >> n;
    string tmp;
    rep(i, n) {
        cin >> tmp;
        mp[tmp]++;
    }
    cin >> m;
    rep(i, m) {
        cin >> tmp;
        mp[tmp]--;
    }
    ll ma = -1 * INF;
    for(auto &&i : mp) {
        ma = max(ma, i.second);
    }
    if(ma < 0)
        cout << 0 << endl;
    else
        cout << ma << endl;
}


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

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, abc: [[i64; 3]; n]);

    let mut dp = vec![vec![0i64; 3]; n + 10];
    for cur in 0..n {
        for i in 0..3 {
            for j in 0..3 {
                if i == j {
                    continue;
                }
                let next = cur + 1;
                dp[next][i] = max(dp[next][i], dp[cur][j] + abc[cur][j]);
            }
        }
    }

    let ans = max(dp[n][0], max(dp[n][1], dp[n][2]));
    println!("{}", ans);
}


Measured memory_bytes: 18684
#!/usr/bin/env python3
import sys


def solve(N: int):
    answer = 0
    for i in range(1,N+1):
        if i%3 == 0 or i%5 == 0:
            continue
        else:
            answer += i
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
# usage:
#   NCR.init(<nの最大値>)
#   NCR.nCr(n, r)
class NCR
  MOD = 10**9+7
  @fac = []
  class << self
    def init(n)
      calc_fact(n)
      # initを呼び忘れたらNoMethodErrorになるよう、ここで定義
      def nCr(n, r)
         (@fac[n] * (mod_inv(@fac[r]) * mod_inv(@fac[n-r])%MOD))%MOD
      end
    end
    def calc_fact(n)
      @fac[0] = 1
      @fac[1] = 1
      i = 2
      while i <= n
        @fac[i] = (@fac[i-1]*i)%MOD
        i += 1
      end
    end
    def power(a, b)
      x = 1; y = a
      while b > 0
        x = (x*y)%MOD if b.odd?
        y = (y*y)%MOD
        b /= 2
      end
      x%MOD
    end
    def mod_inv(n); power(n, MOD-2); end
  end
end

require 'prime'
N, M = gets.split.map &:to_i
if M == 1
  p 1; exit
end
MOD = 10**9+7
factors = Prime.prime_division(M)
n_factors = factors.map(&:last).inject(:+)

NCR.init(29+N-1)

ans = factors.map{|n, times|
  NCR.nCr(times + N-1, times)
}.inject{|a, b|
  a * b % MOD
}
p ans

Measured memory_bytes: 2892
package main

import "fmt"

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

	a := 1
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		a = lcm(a, t)
	}
	fmt.Println(a)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}


Measured memory_bytes: 512
// 参考: http://genkisugimoto.com/jp/blog/procon/2015/04/15/print-debug-technique-in-cpp.html
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

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

    if (S.substr(0, 4) == "YAKI") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
int dist[125252];
vector<pii> g[125252];
bool used[125252];

const int INF = 1145141919;

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    --a;--b;
    g[a].push_back(pii(b,c));
  }
  // dijkstra in 0~n-2
  REP(i,n)dist[i] = INF;
  priority_queue<pii> Q;
  Q.push(pii(-0,0));
  dist[0] = 0;
  int ans = -1;
  while(!Q.empty()){
    pii P = Q.top(); Q.pop();
    int d = -P.first;
    int pos = P.second;
    if(used[pos])continue;
    used[pos] = true;
    REP(i,g[pos].size()){
      int to = g[pos][i].first;
      int c = g[pos][i].second;
      if(c<d)continue;
      if(to==n-1){
        CHMAX(ans,c);
      }else{
        if(dist[to] <= c)continue;
        dist[to] = c;
        Q.push(pii(-c,to));
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 8296
N = int(input())
A = list(map(int, input().split()))
A = [A[n]-n for n in range(N)]
A.sort()
if N % 2 == 1:
  A = [abs(a - A[N//2]) for a in A]
  ans = sum(A)
else:
  temp = A
  A = [abs(a - A[N//2]) for a in A]
  ans = sum(A)
  A = [abs(a - temp[N//2-1]) for a in temp]
  ans = min(ans, sum(A))

print(ans)

Measured memory_bytes: 27432
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int A, B, N;

int Ans() {
  int x = MIN(N, B-1);
  return (A*x)/B - A*(x/B);
}

signed main() {
  cin >> A >> B >> N;

  auto ans = Ans();

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray();
            var N = line[0];
            var M = line[1];
            var D = line[2];
            double prob = 0;

            if (D == 0)
            {
                prob = 1 / N;
            }else
            {
                prob = 2 * (N - D) / Math.Pow(N, 2);
            }

            Console.WriteLine(prob * (M - 1));
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>

using namespace std;




int main(int argc, char *argv[])
{
	int n;
	int ans = 0;
	multiset<int> p;

	cin >> n;


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

		cin >> pi;

		p.insert(pi);
	}



	for (auto itr = p.rbegin(); itr != p.rend(); ++itr) {
		if (itr == p.rbegin()){
			ans += *itr / 2;
		}
		else{
			ans += *itr;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use Data::Dumper;

my @INPUT;
while (<>) {
    chomp;
    push @INPUT, $_;
}

my @S = split "", shift @INPUT;

my @B;
for (my $i = 0; $i < @S; $i++) {
    if ($S[$i] eq 'B') {
        push @B, $i;
    }
}

my $ans = 0;
for (my $i = 0; $i < @B; $i++) {
    $ans += $#S - $B[$i] - ($#B - $i)
}

say $ans;


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 998244353
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

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

const int N=4e5+5;
ll dp[N];
ll rem[N];

void solve(){
	int n,k;
	cin>>n>>k;
	vpii arr(n);
	fr(i,0,k){
		cin>>arr[i].first>>arr[i].second;
	}
	// cout<<arr[0].first<<endl;
	// sort(all(arr));
	// cout<<arr[0].first<<endl;
	dp[1]=1;
	fr(i,1,n+1){
		rem[i]=(rem[i]+rem[i-1])%MOD;
		// cout<<rem[i]<<endl;
		dp[i]=(dp[i]+rem[i])%MOD;
		fr(j,0,k){
			rem[i+arr[j].first]=(rem[i+arr[j].first]+dp[i])%MOD;
			rem[i+arr[j].second+1]=(rem[i+arr[j].second+1]-dp[i]+MOD)%MOD;
		}
	}
	cout<<dp[n]<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; ++i) cin >> a[i];
    vector<long long> le(n-1), ri(n-1);
    long long sle = 0, sri = 0;
    for (int i=0; i<n-1; ++i) {
        sle += a[i];
        le[i] = sle;
    }
    for (int i=n-1; i>0; --i) {
        sri += a[i];
        ri[i-1] = sri;
    }
    long long m = 1e18;
    for (int i=0; i<n-1; ++i) {
        m = min(m, abs(le[i] - ri[i]));
    }
    cout << m << endl;
}

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

string W, S;
int ans;

int main(){
    cin >> W;
    for(int i = 0; i < W.size(); i++) W[i] = tolower(W[i]);
    
    int ans = 0;
    while(cin >> S){
        for(int i = 0; i < S.size(); i++) S[i] = tolower(S[i]);
        if(S == W){ans++;}
    }
    std::cout << ans << std::endl;
    return 0;
}




Measured memory_bytes: 3208
#include <cstdio>
#include <algorithm>
#define ele long
using namespace std;
ele a,b;
inline ele d(ele x){
	if (x==0) return 1;
	ele s=0;
	while (x>0){
		++s;
		x/=10;
	}
	return s; 
}
int main(){
	while (~scanf("%d%d",&a,&b)) printf("%d\n",d(a+b));
	return 0;
}

Measured memory_bytes: 1028
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    vector<int> gathering_child(const string& S) {
        vector<int> key_positions;
        for (int i = 0; i + 1 < S.size(); ++i) {
            if (S[i + 1] != S[i]) {
                key_positions.emplace_back(i);
            }
        }
        vector<int> result(S.size(), 0);
        for (int i = 0; i < S.size(); ++i) {
            if (S[i] == 'R') {
                auto key_pos = *lower_bound(key_positions.begin(), key_positions.end(), i);
                if ((key_pos - i) % 2 == 1) {
                    result[key_pos + 1] += 1;
                } else {
                    result[key_pos] += 1;
                }
            } else {
                auto iter = lower_bound(key_positions.begin(), key_positions.end(), i);
                --iter;
                auto key_pos = *iter;
                if ((i - key_pos) % 2 == 1) {
                    result[key_pos + 1] += 1;
                } else {
                    result[key_pos] += 1;
                }
            }
        }
        return result;
    }
private:

};

int solve() {
    Solution solution;
    // handle IO here
    string S;
    cin >> S;
    auto result = solution.gathering_child(S);
    for (int i = 0; i < result.size() - 1; ++i) {
        cout << result[i] << ' ';
    }
    if (!result.empty()) {
        cout << result.back();
    }
    cout << '\n';
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  sort(p.begin(), p.end());
  ll ans = 0;
  for(int i = 0; i < k; ++i){
    ans += p[i];
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int n, q;
  cin >> n >> q;
  vector<vector<int>> ver(n,vector<int>(0));
  int a, b;
  for(int i=0; i<n-1; ++i){
    cin >> a >> b;
    --a; --b;
    ver[a].push_back(b);
    ver[b].push_back(a);
  }
  int p, x;
  vector<int> Q(n,0);
  for(int i=0; i<q; ++i){
    cin >> p >> x;
    --p;
    Q[p] += x;
  }
  vector<int> ans(n,-1);
  queue<P> que;
  que.push(make_pair(0,Q[0]));
  while(!que.empty()){
    int y = que.front().first;
    int v = que.front().second;
    que.pop();
    ans[y] = v;
    for(int a:ver[y]){
      if(ans[a] == -1) que.push(make_pair(a,v+Q[a]));
    }
  }
  for(int i=0; i<n; ++i){
    if(i != n-1) cout << ans[i] << " ";
    else cout << ans[i] << endl;
  }
}

Measured memory_bytes: 18204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,T,A;
    double d=1e9;
    int f=0;
    cin>>N>>T>>A;
    for(int i=1;i<=N;i++){
        double h;
        cin>>h;
        double val=fabs(A-(T-h*0.006));
        if(val<d) {d=val;f=i;}
    }
    cout<<f;
    return 0;
}


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

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

    int x;
    cin >> x;

    int n = 6;
    vector<int> A = {100, 101, 102, 103, 104, 105};

    vector<bool> F(x + 10);
    F[0] = true;
    for(int i = 0; i < n; i++){
        F[A[i]] = true;
    }

    for(int i = 100; i <= x; i++){
        for(int j = 0; j < n; j++){
            int fm = i - A[j];
            if(fm < 0) continue;
            if(F[fm]) F[i] = true;
        }
    }

    cout << (F[x] ? 1 : 0) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
 
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
 
    if((A+B)%3==0 || A%3==0 || B%3==0){
       	System.out.println("Possible");
    }else {
       	System.out.println("Impossible");
    }
}
}

Measured memory_bytes: 35652
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int n;
	cin >> n;
	if (n % 10 == 9) {
		cout << "Yes";
		return 0;
	}
	if (n / 10 == 9) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
}

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

int main(){
  int N, first_l=0;
  string S;

  cin >> N >> S;

  int left = 0;
  int right = 0;

  // rep(i, N){
  //   if (S[i]==')') left++;
  //   else{
  //     first_l = i;
  //     break;
  //   }
  // }

  rep(i, N){
    if (S[i]=='(') {
      right++;
    }
    else if (right>0){
      right--;
    }
    else{
      left++;
    }
  }

  rep(i,left){
    S = '(' + S;
  }
  rep(i, right){
    S = S + ')';
  }

  cout << S << endl;

}


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

int n, dp[100009][3];

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a;
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b;
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c;
	}
	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << '\n';

	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(a==0 && b==0){
                System.exit(0);
            }
            for(int j=0;j<a;j++){
                for(int i=0;i<b;i++){
                    System.out.printf("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


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

int main(void){

	vector<int>v;
	int n,t,ans=0;
	cin>>n;
	
	
	for(int i=0;i<2*n;i++){
	cin>>t;
	v.push_back(t);
	}
	sort(v.begin(),v.end());
	
	for(int i=0;i<n;i++)
	ans+=min(v[2*i],v[2*i+1]);
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = nextInt()
	}
	sort.Ints(as)

	max := int(1e6)
	var isNotPrime = make([]bool, max+1)
	isNotPrime[0] = true
	isNotPrime[1] = true
	x := 2
	for ; x*x <= max; x++ {
		if !isNotPrime[x] {
			for m := 2; x*m <= max; m++ {
				isNotPrime[x*m] = true
			}
		}
	}

	used := make(map[int]bool)
	am := make(map[int]bool)
	ans := 0
	for i := 0; i < n; i++ {
		if used[as[i]] {
			continue
		}

		var ds []int
		if isNotPrime[as[i]] {
			ds = divisors(as[i])
		} else {
			ds = []int{1, as[i]}
		}
		used[as[i]] = true

		ok := true
		for _, k := range ds {
			if am[k] {
				ok = false
				break
			}
		}
		am[as[i]] = true

		if ok {
			if !(i+1 < n && as[i] == as[i+1]) {
				ans++
			}
		}
	}

	fmt.Println(ans)
}

func divisors(n int) []int {
	ds := make([]int, 0)
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			ds = append(ds, i)
			if i*i != n {
				ds = append(ds, n/i)
			}
		}
	}
	return ds
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 28876
#include<bits/stdc++.h>
using namespace std;
int ans=0;
long long N;
int pow(int a,int b){
  int ans=1;
  if(b==0){
    return 1;
  }
  else{
    for(int i=0;i<b;i++){
      ans = a*ans;
    }
    return ans;
  }
}

int main(){
  cin >>N;
  string n=to_string(N);
    int sum=0,multiple=1;
    for(int j=0;j<n.size();j++){
      sum+=n[j]-'0';
      //multiple*=n[j]-'0';
    }
  if(N%sum==0) 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< (int)(b); ++i)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int h,n;
    cin >> h >> n;
    int a[n];
    rep(i,0,n) cin >> a[i];
    int sum;
    rep(i,0,n) sum += a[i];
    if(h<=sum) cout << "Yes" << "\n";
    else cout << "No" << "\n"; 



}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e4+23;
const int M = 1e6+23;
const int mod = 1e9+7;

int a[N];
int h[M];
vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};

int binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    int x = a[i];
    for (int j = 0; j < (int)primes.size(); ++j) {
      int cnt = 0;
      while (x % primes[j] == 0) {
	x /= primes[j];
	++cnt;
      }
      h[primes[j]] = max(h[primes[j]], cnt);
    }
    h[x] = 1;
  }
  long long l = 1;
  for (int i = 2; i < M; ++i) {
    if (!h[i]) continue;
    l = l * binpow(i, h[i]) % mod;
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = (ans + l * binpow(a[i], mod-2) % mod) % mod;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 6332
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		StringBuilder ans = new StringBuilder();
		
		sc.close();
		
		for(int i=0; 2*i < s.length(); i++) {
			ans.append(s.charAt(2*i));
		}
		
		System.out.println(ans);

	}

}



Measured memory_bytes: 39112
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

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

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	fast;
	int n,m;
	cin >> n >> m;
	int ans = (n*(n-1))/2;
	int ans1 = (m*(m-1))/2;
	cout <<ans+ans1;
}





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

using namespace std;

int main() {
    int n, c; cin >> n >> c;
    long long dp[n + 1][c + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
        int v, w; cin >> w >> v;
        for (int j = 1; j <= c; j++) {
            if (j < w)  
                dp[i][j] = dp[i - 1][j];
            else 
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v);
        }
    }
    cout << dp[n][c];
    return 0;
}

Measured memory_bytes: 82512
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<int>a(N);
  
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if((i % 2 == 0) && (a[i] % 2 != 0)) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3576
using System;
using System.Linq;
class Problem
{
    static void Main(string[] args)
    {
        
        string[] num = Console.ReadLine().Split(' ');
        int N = int.Parse(num[0]);
        int M = int.Parse(num[1]);
        int C = int.Parse(num[2]);

        int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[,] a = new int[N, M];
        int[] preA = new int[M];
      　int i, j;

        for(i=0; i<N; i++)
        {
            preA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for(j=0; j<M; j++)
            {
                a[i, j] = preA[j];
            }
            
        }

        int ans = 0;
        int x = C;

        for(i=0; i<N; i++)
        {
            for(j=0; j<M; j++)
            {
                x += a[i, j] * b[j];
            }
            if (x > 0){
                ans += 1;
            }
            x = C;
        }
        Console.WriteLine(ans);
    }
}

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

int main(){
    int h,n;
    cin >> h >>n;
    int dp[h+1];
    rep(i,h+1) dp[i]=1000000000;
    dp[0]=0;
    rep(i,n){
        int a,b;
        cin >> a >>b;
        rep(j,h){
            int k=min(h,a+j);
            dp[k]=min(dp[k],dp[j]+b);
        }
    }

    cout << dp[h] << endl;

}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    ll N;
    cin >> N;

    string res = "";
    while (N > 0) {
        --N;
        char c = (char)('a' + N%26);
        res = c + res;
        N /= 26;
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(){
	int n,i,j,w,cnt;
	int d[100];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	
	for(i=0;i<n;i++){
		for(j = n-1;j>i;j--){
			if(d[j-1] > d[j]){
				w = d[j-1];
				d[j-1] = d[j];
				d[j] = w;
			}
		}
	}
	
	cnt = 1;
	for(i=0;i<n-1;i++){
		if(d[i] != d[i+1])cnt++;
	}
	
	printf("%d\n",cnt);
	
	return 0;
}

Measured memory_bytes: 128
/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is quite cool.It becomes cooler when you enjoy learning new things
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define pool(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int x;
  cin>>x;
  if(x)
    cout<<"0"<<endl;
  else
    cout<<1<<endl;
} 

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define maxl 100010

using namespace std;

int n,m,ans;
int a[maxl];
struct ed
{
	int u,v,val;
}e[maxl];
int f[maxl],cnt[maxl];
long long sum[maxl];

inline bool cmp(const ed &x,const ed &y)
{
	return x.val<y.val;
}

inline void prework()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		f[i]=i;cnt[i]=0;sum[i]=a[i];
	}
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].val);
	sort(e+1,e+1+m,cmp);
}

inline int find(int x)
{
	if(f[x]!=x)
	{
		f[x]=find(f[x]);
		cnt[f[x]]+=cnt[x];
		sum[f[x]]+=cnt[x];
		sum[x]=cnt[x]=0;
	}
	return f[x];
}

inline void mainwork()
{
	int x,y,xx,yy;
	for(int i=1;i<=m;i++)
	{
		x=e[i].u;y=e[i].v;
		xx=find(x);yy=find(y);
		if(xx!=yy)
		{
			cnt[xx]+=cnt[yy]+1;
			sum[xx]+=sum[yy];
			f[yy]=xx;
			sum[yy]=0;cnt[yy]=0;
			if(sum[xx]>=e[i].val)
			{
				ans+=cnt[xx];
				cnt[xx]=0;
			}
		}
		else
		{
			cnt[xx]++;
			if(sum[xx]>=e[i].val)
			{
				ans+=cnt[xx];
				cnt[xx]=0; 
			}
		}
	}
}

inline void print()
{
	printf("%d",m-ans);
}

int main()
{
	prework();
	mainwork();
	print();
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI t(n), a(n);
	rep(i,n) cin >>t[i];
	rep(i,n) cin >>a[i];
	

	if(t.back() != a.front()) {puts("0"); return 0;}
	
	VI kt(n, -1), ck(n , -1);
	kt[0] = t.front(); kt.back()=a.back();
	rep(i,n-1) if(t[i] < t[i+1]) kt[i+1] = t[i+1];
	repr(i,n-1,0) if(a[i] > a[i+1]){
		if(kt[i] !=-1 && kt[i] != a[i]) {puts("0"); return 0;}
		kt[i] = a[i];
	}
	
	rep(i,n) if(kt[i]>=0){
		if(kt[i] > a[i] || kt[i] >t[i]) {puts("0"); return 0;}
	}
	
	if(n==1) {puts("1"); return 0;}
	
	//for(auto x :kt) printf("%d, ",x); puts("");
	ll ans  = 1;
	rep(i,n){
		if(kt[i]==-1){
			ans *= (ll)min(a[i],t[i]);
			ans %= mod ;
		}
	
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;
int n,q,m,k,l,ans;
vi a,b;
ll llans;
vll lla,llb;
string s;

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

    cout << ( X- B * (X/B)) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#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
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int x,y;
	cin>>x>>y;
	if(y&1)
	{
	cout<<"No";
	}
	else{
		int l,r;
		l=x+x;
		r=l+l;
		if(y>r||y<l){
			
	cout<<"No";
		}
		else{
			cout<<"Yes";
		}
	}
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  X,Y;
  cin>>X>>Y;
  if (Y<=X*4 && Y>=X*2 && Y%2==0){
    cout <<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, x;
    int a[2005];
    int b[2005][2005];
    int mins[2005];
    int ans = INF;

    cin >> n >> x;
    rep(i, n) cin >> a[i];
    rep(i, n) {
        rep(j, n) {
            if (i - j >= 0) b[i][j] = a[i - j];
            else b[i][j] = a[n - (i - j) * -1];
        }
    }
    rep(i, n) mins[i] = INF;
    rep(i, n) {
        rep(j, n) {
            chmin(mins[j], b[j][i]);
        }
        int cnt = 0;
        rep(j, n) cnt += mins[j];
        cnt += x * i;
        chmin(ans, cnt);
    }
    cout << ans << endl;;

    return 0;
}


Measured memory_bytes: 31616
import numpy as np
import itertools
import math

N = int(input())
cities = [list(map(int, input().split())) for _ in range(N)]
total_length = 0

for Root in list(itertools.permutations(cities)):
  xi, yi = Root[0][0], Root[0][1]
  for xj, yj in Root[1:]:
    total_length += np.sqrt((xi - xj)**2 + (yi - yj)**2)

print(total_length / math.factorial(N))

Measured memory_bytes: 16996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    int N,M;
	cin >> N>>M;
    string s;
    int p;
    set<int> ac_set;
    vector<int> miss(N);
    int ac_num = 0;
    int miss_num = 0;
    for(int i=0;i<M;i++){
        cin >>p>>s;
        if(s=="AC"){
            if(ac_set.count(p)==0){
                ac_set.insert(p);
                ++ac_num;
                miss_num+=miss[p];
            }
        }else{
            miss[p]+=1;
        }
    }

	cout<<ac_num<<" "<<miss_num<<"\n";

	return 0;
}

Measured memory_bytes: 5376