akhauriyash/Code-Regression huggingface dataset:
// -----問題文-----
// 長さNの値のわからない整数列Aがあります。長さN-1の整数列Bが与えられます。
// この時、Bi≧max（Ai, Ai+1）が成立することが分かっています。
// Aの要素の総和として考えらえる値の最大値を求めてください。
// -----制約-----
// ・入力は全て整数
// ・2≦N≦100
// ・0≦Bi≦10^5
// -----入力-----
// N
// B1 B2 .... BN-1
// -----出力-----
// Aの要素の総和として考えられる値の最大値を出力せよ。
#include<stdio.h>

// 配列情報格納に使用
int b[101], a[101];
// min() 小さいほうを返す
int min(int a, int b){
	return (a < b ? a : b);
}

int main() {
    int n;
    scanf("%d", &n);
	for(int i = 0; i < n-1; i++) {
        scanf("%d", &b[i]);
    }
    // Bi≧max(Ai, Ai+1)、Bi+1≧max(Ai+1, Ai+2)より、、
    // Ai+1≦min(Bi, Bi+1)となるから、Ai≦min(Bi-1, Bi)となる。
    // A1≦min(null, B1)、AN≦min(BN-1, null)で配列が完成する。
    // よって、要素の総和が最大となる配列を求めることができる。
    for(int i = 1; i < n - 1; i++) {
        a[i] = min(b[i - 1], b[i]);
    }
	a[0] = b[0]; 
    a[n - 1] = b[n - 2];

	int sum = 0;
	for(int i = 0; i < n; i++) sum += a[i];
	printf("%d\n", sum);
}

Measured memory_bytes: 128
n = int(input())
x = list(map(int, input().split()))

p_1 = sum(x) // n
p_2 = p_1 + 1

ans_1 = 0
ans_2 = 0

for x_i in x:
  ans_1 += (x_i - p_1) ** 2
  ans_2 += (x_i - p_2) ** 2

print(min(ans_1, ans_2))

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    ll B[101];
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        cin >> B[i];
    }
    ll cnt = B[0];
    for (int i = 1; i < N-1; i++) {
        cnt += min(B[i-1],B[i]);
    }
    cout << cnt+B[N-2] << endl;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class UnionFind {
    vector<int> data;
    int num;

  public:
    UnionFind(int size) : data(size, -1), num(size) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if(x != y) {
            if(data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
            num--;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
    int numSet() {
        return num;
    }
};

void solve() {
    ll n, m;
    cin >> n >> m;
    UnionFind uni(n + m);
    Array ls(m, false);
    ll num = n;
    REP(i, n) {
        ll k;
        cin >> k;
        REP(j, k) {
            ll l;
            cin >> l;
            l--;
            if(!ls[l]) {
                ls[l] = true;
                num++;
            }
            uni.unionSet(i, n + l);
        }
    }

    if(uni.size(0) == num)
        cout
            << "YES" << en;
    else
        cout << "NO" << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 4728
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(N) for (int i = 0; i < N; i++)

int main() {
    int N, A;
    cin >> N;
    int count = 0;
    map<int, int> paper;
    for (int i = 0; i < N; i++){
        cin >> A;
        if (paper.find(A-1) != paper.end()){
            paper[A-1]++;
        }else{
            paper[A-1] = 1;
        }
    }

    for (auto element = paper.begin(); element != paper.end(); ++element){
        if (element->second % 2 == 1) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void){

    int a, b;
    scanf("%d %d",&a,&b);

    if(a==b)
        printf("a == b\n");
    else if(a<b)
        printf("a < b\n");
    else if(a>b)
        printf("a > b\n");
    else
        printf("Error has occurred.\n");

    return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int check[4] = {0};
  for(int i = 0;i < n;i++) {
    char c;
    cin >> c;
    if(c == 'P')
      check[0] = 1;
    if(c == 'G')
      check[1] = 1;
    if(c == 'Y')
      check[2] = 1;
    if(c == 'W')
      check[3] = 1;
  }
  int sum = 0;
  for(int i = 0; i < 4; i++)
    sum += check[i];
  if(sum == 3)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
}



Measured memory_bytes: 256
s = input().split(" ")
n = int(s[0])
q = int(s[1])

class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

queue = []

for i in range(n):
    t = input().split(" ")
    queue.append(Process(t[0], int(t[1])))
   
head = 0
tail = n-1

def dequeue():
    global head
    x = queue[head]
    head = (head + 1) % n
    return x
    
def enqueue(x):
    global tail
    tail = (tail + 1) % n
    queue[tail] = x

time = 0

while head != tail:
    w = dequeue()
    if w.time > q:
        w.time = w.time - q
        time = time + q
        enqueue(w)
    else:
        time = time + w.time
        print("{0} {1}".format(w.name, time))
print("{0} {1}".format(queue[head].name, time+queue[head].time))

Measured memory_bytes: 19176
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)...}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__) << '\n'
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on





auto Main() {
	int n,k;
	cin>>n>>k;
	
	vector<int> S(n,1);
	FOR(i,0,k) {
		int d=Cin;
		FOR(di,0,d) {
			int a = Cin;
			S[a-1]=0;
		}
	}

	cout << accumulate(begin(S), end(S), 0);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


Measured memory_bytes: 3656
Scanf.scanf "%d" (fun t ->
    for ii = 1 to t do
        Scanf.scanf " %d" (fun n ->
            let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
            Scanf.scanf " %s" (fun s ->
                let rec loop i li =
                    if i < 0 then 0 else
                        let v = List.fold_right (fun v acc -> min acc (acc lxor v)) li a.(i) in 
                        if v = 0 then loop (i - 1) li else
                            if s.[i] = '0' then loop (i - 1) (v :: li) else 1
                in
                loop (n - 1) [] |> Printf.printf "%d\n"
            )
        )
    done
)

Measured memory_bytes: 5924
using System;

public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var m = int.Parse(input[1]);
        
        Console.WriteLine(n * (n- 1) /2 + m * (m-1) / 2);
    }
}

Measured memory_bytes: 13140
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if (self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if (x == y):
            return
            # 違う木に属していた場合rnkを見てくっつける方を決める
        elif (self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if (self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

    def members(self, x):
        root = self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.root) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def size(self, x):
        return -self.root[self.Find_Root(x)]


n, m, k = map(int, input().split())

uf = UnionFind(n)
directcount = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    directcount[a] += 1
    directcount[b] += 1
    uf.Unite(a, b)

res = []
for _ in range(n):
    res.append( [0, -1] )
ures = []

for i in range(n):
    res[i][0] = uf.size(i) - directcount[i] -1
    res[i][1] = uf.Find_Root(i)
#print(res)


for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if res[c][1] == res[d][1]:
        res[c][0] -= 1
        res[d][0] -= 1


print(" ".join(list(map(lambda x: str(x[0]), res))))


Measured memory_bytes: 102104
<?php
fscanf(STDIN, "%d %d", $n, $max);
for( $i=0; $i<$n; $i++ )
{
  list( $price, $num )  = explode(" ", trim(fgets(STDIN)) );
  if( isset($shopList[$price]) )
  { $shopList[$price] += $num; }
  else
  { $shopList[$price] = $num; }
}
ksort( $shopList );

$sum = 0;
foreach( $shopList as $price => $num )
{
  $buy = min( $max, $num );
  $max -= $buy;
  $sum += $buy*$price;

  if( $max == 0 ) { break; }
}

echo $sum;
?>

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


int main()
{
    int t=1;
    //cin>>t;


    while( t-- )
    {
        int n;
        cin>>n;

        int r=n%10;

        if( r==2 || r==4 || r==5 || r==7 || r==9 )
            cout<<"hon"<<endl;
        else if( r==0 || r==1 || r==6 || r==8 )
            cout<<"pon"<<endl;
        else
            cout<<"bon"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	string str1,str2;
	cin>>str1>>str2;
  ll i=0,ans=0;
  for(i=0;i<3;i++){
    if(str1[i]==str2[i]){
      ans++;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	var ans int
	N := nextInt()
	M := nextInt()
	conditions := make([]int, N)
	nums := make([]int, N)
	if M == 0 {
		if N == 1 {
			fmt.Println(0)
			return
		}
		nums[0] = 1
		for i := 0; i < N; i++ {
			ans += nums[len(nums)-i-1] * int(math.Pow10(i))
		}
		fmt.Println(ans)
		return
	}
	for i := 0; i < M; i++ {
		s := nextInt() - 1
		c := nextInt()
		if conditions[s] == 1 && nums[s] != c {
			fmt.Println(-1)
			return
		}
		if N != 1 && s == 0 && c == 0 {
			fmt.Println(-1)
			return
		}
		nums[s] = c
		conditions[s] = 1
	}
	if conditions[0] == 0 {
		nums[0] = 1
	}
	if N != 1 && nums[0] == 0 {
		fmt.Println(-1)
		return
	}
	for i := 0; i < N; i++ {
		ans += nums[len(nums)-i-1] * int(math.Pow10(i))
	}
	if ans >= 0 {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

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


Measured memory_bytes: 32128
"""
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)

def iin(): return int(input())
def lin(): return list(map(int, input().split()))

# range = xrange
# input = raw_input


def main():
    h, n = lin()
    a = [lin() for i in range(n)]
    ans = [-1]*(h+1)
    ans[0] = 0
    for i in range(1, h+1):
        ans[i] = min([
            ans[max(0, i-j)]+k for j, k in a
            ])
        
        
    print(ans[h])



            
        

        
main()
# threading.Thread(target=main).start()


Measured memory_bytes: 43748
a=[]
for i in 0..4
  a[i]=gets.chomp.to_i
end

min=20000

a.permutation(5).each do |arr|
  t=0
  for i in 0..4
    
    if t%10==0
      t+=arr[i]
    else
      t+=arr[i]+10-t%10
    end
  end


  if min > t
    min=t
  end

end

puts min

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, m;
	cin >> n;
	VI a(n); rep(i, n)cin >> a[i];
	cin >> m;
	VI b(m); rep(i, m)cin >> b[i];

	VI re;
	set_union(all(a), all(b), inserter(re, end(re)));
	for (auto x : re)cout << x << endl;
}


Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int[] split = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string s = Console.ReadLine();
        string output = "";
        for (int i = 0; i < s.Length; i++)
            output += (i == split[1] - 1) ? s[i].ToString().ToLower() : s[i].ToString();
        Console.WriteLine(output);
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 1000000007
#define N 100005
#define PI 3.14159265
bool compare(pair<ll,ll> i, pair<ll,ll> j) 
{
  return i.S < j.S;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
}
int main()
{
	ll h,a;
  	cin>>h>>a;
  	if(h%a==0)
      	cout<<h/a;
  	else
      	cout<<(ll)h/a+1;
  	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
MAX = 10**15+1
a_min = MAX

for i in range(5):
    a = int(input())
    A.append(a)
    if a_min > a:
        a_min = a

print(N//a_min-1+(1 if N%a_min>0 else 0)+5)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  string S; cin >> S;

  vector<vector<bool>> ans(3);
  ans[0].resize(10);
  ans[1].resize(100);
  ans[2].resize(1000);

  for (char c : S) {
    int x = c - '0';
    REP(i, 100) {
      if (ans[1][i]) {
        ans[2][i * 10 + x] = true;
      }
    }
    REP(i, 10) {
      if (ans[0][i]) {
        ans[1][i * 10 + x] = true;

      }
    }
    ans[0][x] = true;
  }

  int num = 0;
  REP(i, 1000) num += ans[2][i];
  cout << num << endl;
  return 0;
}


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

int main(){
    int n,sum=0;
    int a[10010];
    cin>> n;
    for(int i=0; i< n; i++){
        cin >> a[i];
    }
    for(int i=0; i< n; i++){
        sum += a[i]-1;
    }
    cout << sum <<endl;
    return 0;
}

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	int d[n];
	for(int i=0;i<n;i++){
		cin >> d[i];
	}
	sort(d,d+n);
	// keisan
	cout << d[n/2] - d[n/2-1];
	// syutsuryoku
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

char abc[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
vector<string> s;
int n;

void solve(int cnt, string now, int t){
    cnt++;
    rep(i, t){
        if(cnt == n){
            s.push_back(now+abc[i]);
        }
        else{
            if(i == t-1)solve(cnt, now+abc[i], t+1);
            else solve(cnt, now+abc[i], t);
        }
    }
    return;
}

int main() {
    cin >> n;
    solve(0, "", 1);
    sort(all(s));
    rep(i, s.size()){
        cout << s[i] << endl;
    }
}   


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    vector<i64> matched;
    REP(i, S.length()) {
        if (i + T.length() > S.length()) break;
        bool match = true;
        REP(j, T.length()) {
            if (S[i + j] == T[j] || S[i + j] == '?') continue;
            match = false;
            break;
        }
        if (match) matched.pb(i);
    }

    if (matched.size() == 0) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string ans = "-";
    REP(k, matched.size()) {
        i64 mi = matched[k];
        string candid = S.substr(0, mi) + T + S.substr(mi + T.length());
        REP(i, candid.length()) {
            if (candid[i] == '?') candid[i] = 'a';
        }
        if (ans == "-") ans = candid;
        chmin(ans, candid);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <string>



using namespace std;

char s[110];
int szS;

string target;

int main()
{
	scanf("%s", s);
	szS = strlen(s);
	string ss = s;
	
	int delDepth = szS - 7;
	if (delDepth == 0)
	{
		if (ss == "keyence")
			printf("YES\n");
		else
			printf("NO\n");
		return 0;
	}
	
	for (int i = 0 ; i < szS - delDepth ; i++)
	{
		target = ss.substr(0, i) + ss.substr(i + delDepth);
		if (target == "keyence")
		{
			printf("YES\n");			
			return 0;
		}


	}
	
	
	printf("NO\n");	
	
	
	return 0;
}



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

typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;

int main()
{
    ll n, a, b, blue, val, ans = 0 ;
    cin >> n >> a >> b ;
    val = a + b ;
    blue = n / val ;
    ans += (blue * a) ;
    n -= (blue * val) ;
    ans += min(n, a) ;
    cout << ans ;

}


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


int main(){
  int A , B ; 
  cin >> A >> B ; 
  
  int cnt = 0 ; 
  
  for(int i = A ; i <= B ; i++){
    int T = 0 ; 
    string S = to_string(i) ;
    for(int j = 0 ; j < S.size() ; j++){
      if(S.at(j) != S.at(S.size() - 1 - j )){
        T++ ; 
      }
    }
    
    if(T ==  0 ){
      cnt++ ; 
    }
         
    
  }
  
  cout << cnt << endl ; 
  
}

Measured memory_bytes: 3632
type color = Black | White
type node = {color: color option; children: (int * int) list}

let from_white tree =
  let rec inner aux idx =
    match tree.(idx).color with
    | Some _ -> ()
    | None ->
       if aux mod 2 = 0 then
         begin
           tree.(idx) <- {tree.(idx) with color = Some White};
           List.iter (fun (idx', w) -> inner (aux + w) idx') tree.(idx).children
         end
       else 
         begin
           tree.(idx) <- {tree.(idx) with color = Some Black};
           List.iter (fun (idx', w) -> inner (aux + w) idx') tree.(idx).children
         end
  in inner 0 0; tree

let str_of_color = function None -> "N" | Some Black -> "1" | Some White -> "0"

let tree_to_answer tree =
  Array.iter (fun node -> node.color |> str_of_color |> print_endline) tree

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let tree = Array.make n {color = None; children = []} in
  for i = 1 to n - 1 do 
    Scanf.scanf "%d %d %d\n"
      (fun u v w ->
        tree.(u-1) <- {color=None; children = (v-1, w)::tree.(u-1).children};
        tree.(v-1) <- {color=None; children = (u-1, w)::tree.(v-1).children}
      )
  done;
  from_white tree
  |> tree_to_answer


Measured memory_bytes: 23296
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
        String s="";
        while(in.hasNext()) s+=in.nextLine();
        s=s.replace(" ","").toLowerCase();
		char[] a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        for(char c:a){
        	int r=0;
        	for(int i=0;i<s.length();i++){
            	if(s.charAt(i)==c) r+=1; 
        	}
        	System.out.println(c+" : "+r);
        }
	}
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

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

Measured memory_bytes: 256
=begin
H W
=end
h, w = gets.chomp.split(" ").map(&:to_i)

a = (w + 1) / 2
b = w / 2

if (h == 1) || (w == 1)
  puts 1
  exit
end

if (h % 2 == 0)
  puts((a + b) * (h / 2))
else
  puts((a + b) * (h / 2) + a)
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  int64_t N;
  cin>>N;
  auto k=func(N);
  int ans=0;
  for(auto a:k){
    int t=a.second;
    int tmp=1,count=0;
    while(t>=tmp){t-=tmp;tmp++;count++;}
    ans+=count;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>

int main () {
	int l, r, d;
	int ctr = 0;
	scanf("%d", &l);
	scanf("%d", &r);
	scanf("%d", &d);
	
	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			ctr++;
		}
	}
	printf("%d", ctr);
	
	
	return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    while (true) {
        int q;
        cin >> q;
        if (q == -1) {
            break;
        }
        double x = q / 2.0;
        while (fabs(pow(x, 3) - q) >= q * 0.00001) {
            x -= (pow(x, 3) - q) / 3 / pow(x, 2);
        }
        printf("%f\n", x);
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int n,k;
	cin>>n>>k;
	if(n%k==0){
		cout<<0<<endl;
	}
	else{
		cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int max(int a, int b){
    if(a > b){
        return a;
    }
    else{
        return b;
    }
}

int main(){
    while(1 == 1){
	int n, m, i, j, k, tmp;
	int result = 0;
	scanf("%d%d", &n, &m);
	if(n == 0 && m == 0)
	    break;
	int a[n];
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for(int i = 0; i < n; i++){
	    for (j = i + 1; j < n; j++){
	        tmp = a[i] + a[j];
	        if(tmp <= m){
	            result = max(result, tmp);
	        }
	    }
	}
	if(result != 0){
	    printf("%d\n", result);
	}
	else{
	printf("NONE\n");
    }
    }
	return 0;	
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 15, M = 10;

int k;
int res[N];

void dfs(int len, int u)
{
	if (len == u)
	{
		k -- ;
		if (k == 0)
		{
			for (int i = 0; i < u; i ++ ) cout << res[i];
			puts("");
			exit(0);
		}
		return;
	}
	
	for (int i = 0; i < M; i ++ )
		if (!u && i || u && abs(res[u - 1] - i) <= 1)
		{
			res[u] = i;
			dfs(len, u + 1);
		}
}

int main()
{
	cin >> k;
	for (int i = 1; i < N; i ++ ) dfs(i, 0);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1000000000000000000;
typedef pair<int, int> P;
vector<long long> A, B;
int main(){
	long long n, a, b;
	int i;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a;
		A.push_back(a);
	}
	for (i = 0; i < n; i++) {
		cin >> b;
		B.push_back(b);
	}
	long long sum1, sum2; sum1 = 0; sum2 = 0;
	for (i = 0; i < n; i++) {
		if (A[i] > B[i])sum2 += A[i] - B[i];
		else if (A[i] < B[i]) {
			if ((B[i] - A[i]) % 2 == 1) {
				B[i] += 1; A[i] += 2;
			}
			sum1 += ((B[i] - A[i]) / 2);
		}
	}
	if (sum1 >= sum2) {
		cout<<"Yes" << endl;
	}
	else {
		cout<< "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            decimal W = line[0], H = line[1], x = line[2], y = line[3];

            Console.WriteLine($"{W*H/2} {(x + x == W && y + y == H ? 1 : 0)}");
        }
    }
}

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

int main() {
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  
  cout << w * h / 2.0 << " " ;
  
  if(2 * (int)x == (int)w && 2 * (int)y == (int)h)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
xy=[]
for _ in range(m):
    x,y=map(int,input().split())
    xy.append([x,y])

ball=[1]*n
red=[0]*n
red[0]+=1

for i in range(m):
    if red[xy[i][0]-1]>=1:
        if ball[xy[i][0]-1]==1:
            red[xy[i][0]-1]=0
        red[xy[i][1]-1]+=1
    ball[xy[i][0]-1]-=1
    ball[xy[i][1]-1]+=1

ans=len(red)-red.count(0) 
print(ans)

Measured memory_bytes: 25296
okashimochi_set = set()
N_set = set()

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

for n in range(N):
    N_set.add(n + 1)
    n = n + 1

for i in range(K):
    d = int(input())
    A = input().split()
    for a in range(d):
        okashimochi_set.add(A[a])

result = len(N_set) - len(okashimochi_set)
print(result)

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> a(2,vector<int>(n));
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    
    vector<int> csum1(n+1,0);
    vector<int> csum2(n+1,0);
    for(int i=0;i<n;i++){
        csum1[i+1]=csum1[i]+a[0][i];
        csum2[i+1]=csum2[i]+a[1][i];
    }
    int max=0;
    for(int i=0;i<n;i++){
        int sum=csum1[i+1]+csum2[n]-csum2[i];
        if(max<sum){
            max=sum;
        }
    }
    cout<<max<<endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	
	vector<int> P(N);
	for (int i = 0; i < N; i++) cin >> P.at(i);

	int answer = 0;

	for (int i = 1; i <= N - 2; i++) {
		if (P[i] > P[i - 1] && P[i] < P[i + 1]) answer++;
		else if (P[i]<P[i - 1] && P[i]>P[i + 1]) answer++;
	}

	cout << answer << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int a[3][3];
	for (int i = 0;i < 3;i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}

	int n;
	cin >> n;
	vector<int> b(n);

	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}

	for (int i = 0;i < n;i++) {		
		for (int j = 0;j < 3;j++) {
			for (int k = 0;k < 3;k++) {
				if (b[i] == a[j][k]) {
					a[j][k] = 0;
				}
			}
		}
	}

	for (int i = 0;i < 3;i++) {
		if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	for (int i = 0;i < 3;i++) {
		if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) {
		cout << "Yes" << endl;
		return 0;
	}

	if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    string s;
    cin >> s;
    int n=s.size();
    int q;
    cin >> q;
    bool b=0;
    string sa,sb;
    rep(i,q){
        int x;
        cin >> x;
        if(x==1){
            b=(!b);
            continue;
        }
        int y;
        char c;
        cin >> y >> c;
        if(b){
            if(y==1) sb+=c;
            else sa+=c;
        }
        else{
            if(y==2) sb+=c;
            else sa+=c;
        }

    }
    reverse(all(sa));
    sa+=s;
    sa+=sb;
    if(b) reverse(all(sa));
    cout << sa << endl;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  map<int,set<int>> A;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    A[a].insert(b);
  }
  for(int i:A[1]){
    if(A[i].count(N)){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 28416
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define forn(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD int(1e9+7)
using namespace std;

typedef long long int ll;

bool cmp(int a, int b) {
    return a < b;
}

void printV(vector<int> nums) {
    for (int i: nums) {
        printf("%d ", i);// << " ";
    }
    printf("\n");
}

// void printV(vector<ll> nums) {
//     for (ll i: nums) {
//         printf("%lld ", i);// << " ";
//     }
//     printf("\n");
// }



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);cout.tie(0);
    // time_t start, end;
    // time(&start);
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    for (int i=0; i<=k; i++) {
        for (int j=0; j<=k; j++) {
            if (i+j <= s && s-(i+j) <= k && s-(i+j) >= 0)
                cnt++;
        }
    }
    cout << cnt << endl;
    // time(&end); 
    // double time_taken = double(end - start);
    // cout << "Time Taken: " << fixed << time_taken << setprecision(5);
    // cout << " sec" << endl;
    return 0;
}  

Measured memory_bytes: 3608
<?php   
   fscanf(STDIN,"%s",$w);
   $re=array();
	for($i=0;$i<strlen($w);$i++){
      $re[$w[$i]]++;
    }


foreach($re as $v){
  if($v%2!=0){
    echo "No\n";
    exit;
  }
}

echo "Yes\n";

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll convi(ll n,ll r)
{
    if(n<r){
        return 1;
    }
    else{
        ll numerator = 1;
        for(int i = 0;i<r;i++){
            numerator = numerator * (n-i);
        }
        ll denominator = 1;
        for(int i = 1;i<=r;i++){
            denominator = denominator * i;
        }
        return numerator/denominator;
    }
}

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

    vector<int> snum(n);
    vector<int> nc(10,0);
    vector<vector<int>> ncrange(n,vector<int>(10,0));
    vector<int> nml(10,-1);
    vector<int> nmr(10,-1);
    ll ans = 0;

    REP(i,s.size()){
        snum[i] = s[i] - '0';
    }
    REP(i,s.size()){
        nc[snum[i]]++;
    }
    
    ncrange[0][snum[0]]++;
    FOR(i,1,n){
        REP(j,10){
            if(j == snum[i]){
                ncrange[i][j] = ncrange[i-1][j] + 1;
            }
            else{
                ncrange[i][j] = ncrange[i-1][j];
            }
        }
    }

    REP(i,10){
        REP(j,snum.size()){
            if(snum[j] == i){
                nml[i] = j;
                break;
            }
        }
    }

    REP(i,10){
        REPR(j,snum.size()-1){
            if(snum[j] == i){
                nmr[i] = j;
                break;
            }
        }
    }
    
    REP(i,nml.size()){
        if(nml[i] == -1){
            continue;
        }
        REP(j,nmr.size()){
            if(nml[i] >= nmr[j]){
                continue;
            }
            REP(k,10){
                if(ncrange[nmr[j]-1][k] - ncrange[nml[i]][k] > 0){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define il inline
#define rg register
using namespace std;
typedef long long LL;
const LL m_63=1061109567;
const LL m_127=2139062143;
const int inf=2147483647;
const double pi=atan(1.0)*4.0;
const LL llf=9223372036854775807;
const LL N=1e6+7;
const int M=1e6;
int n,d[N],flag[N];
int num,b[N],w[N],p[N],nt[N];
il LL read(){
    LL x(0),ff(1);char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')ff=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*ff;
}
il void fre(){
	freopen("6.in","r",stdin);
//	freopen("magic.out","w",stdout);
}
il void spfa(){
	queue<int>q;
	memset(d,127,sizeof(d));
	memset(flag,0,sizeof(flag));
	q.push(1);d[1]=0;
	while(!q.empty()){
		int k=q.front();q.pop();
		int e=p[k];flag[k]=0;
		while(e){
			int kk=b[e];
			if(d[kk]>d[k]+w[e]){
				d[kk]=d[k]+w[e];
				if(!flag[kk]){
					flag[kk]=1;
					q.push(kk);
				}
			}
			e=nt[e];
		}
	}
}
il void add(int x,int y,int z){b[++num]=y,w[num]=z,nt[num]=p[x],p[x]=num;}
int main(){
//	fre();
//	cout<<sum(112)<<endl;return 0;
//https://www.luogu.org/problemnew/solution/AT3621
//https://blog.csdn.net/winter2121/article/details/81393967
//Ã¿Ò»¸öÊý¶¼¿ÉÒÔÓÉ1Í¨¹ýÒÔÏÂÁ½ÖÖÊµÏÖ
//*10 Î»ÊýºÍ²»±ä
//+1 Î»ÊýºÍ+1
//	n=read();
//	for(rg int i=1;i<=n;++i){
		int k=read();
		for(rg int j=0;j<k;++j){
			add(j,(j+1)%k,1);
			add(j,(j*10)%k,0);
//			cout<<i<<' '<<(i+1)%k<<" 1"<<endl;
//			cout<<i<<' '<<(i*10)%k<<" 0"<<endl;
		}
		spfa();
		printf("%d\n",d[0]+1);
//		memset(p,0,sizeof(p));num=0;
//	}
	return 0;
}
/*
5 6 10
1 2 4
1 4 1
4 3 1
2 5 1
4 5 2
3 2 1
1
3
1
2 2

*/

Measured memory_bytes: 22528
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class UnionFindTree
  attr_accessor:par,:rank
  def initialize(n)
    @par=Array.new(n){|i| i}
    @rank=array(n,1,0)
  end

  def find(x)
    return x if @par[x]==x
    @par[x]=find(@par[x])
    return @par[x]
  end

  def union(x,y)
    x=find(x)
    y=find(y)
    return if x==y
    if @rank[x]<@rank[y]
      @par[x]=y
    else
      @par[y]=x
      @rank[x]+=1 if @rank[x]==@rank[y]
    end
  end

  def same?(x,y)
    return find(x)==find(y)
  end
end

class Edge
  attr_accessor:to,:from,:c
  def initialize(from,to,cost)
    @from=from
    @to=to
    @c=cost
  end
end

n=gets.to_i
edges=array(2*(n-1),1)
x_arr=array(2,n)
y_arr=array(2,n)
n.times do|i|
  x,y=get_i
  x_arr[i]=[x,i]
  y_arr[i]=[y,i]
end
x_arr.sort!{|a,b| a[0]<=>b[0]}
y_arr.sort!{|a,b| a[0]<=>b[0]}
(n-1).times do|i|
  edges[i]=Edge.new(x_arr[i][1],x_arr[i+1][1],(x_arr[i+1][0]-x_arr[i][0]))
end
(n-1).times do|i|
  edges[i+n-1]=Edge.new(y_arr[i][1],y_arr[i+1][1],(y_arr[i+1][0]-y_arr[i][0]))
end
uft=UnionFindTree.new(n)
edges.sort!{|a,b| a.c<=>b.c}
ans=0
m=edges.size
m.times do|i|
  e=edges[i]
  unless uft.same?(e.to,e.from)
    uft.union(e.to,e.from)
    ans+=e.c
  end
end
puts ans

Measured memory_bytes: 33620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------
int main(){
  int n,a,b,ans;
  cin>>n>>a>>b;
   ans=0;
  ans=min(n*a,b);
cout<<ans<<endl;
}


Measured memory_bytes: 256
import scala.collection.mutable


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = mutable.ArrayBuffer.fill(n)(sc.nextInt())
    println(a.mkString(" "))
    for (i <- 1 to n - 1) {
      val v = a(i)
      var j = i - 1
      while (j >= 0 && a(j) > v) {
        a(j + 1) = a(j)
        j -= 1
        a(j + 1) = v
      }
      println(a.mkString(" "))
    }

  }
}




Measured memory_bytes: 48124
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 

    fast;

    string s;
    cin>>s;

    set<ll> rt,lt;

    for(ll i=0;i<s.size();i++)
    {
      if(s[i]=='R')
        rt.insert(i);
      else lt.insert(i);
    }

    ll d[s.size()];
    memset(d,0,sizeof(d));

    for(auto i:rt)
    {
      ll x=*lt.upper_bound(i);
      if((x-i)%2==0)
        d[x]++;
      else d[x-1]++;
    }

    for(auto i:lt)
    {
      auto itr=rt.upper_bound(i);
      itr--;
      ll x=*itr;

      if((i-x)%2==0)
        d[x]++;
      else d[x+1]++;
    }

    for(ll i=0;i<s.size();i++)
      cout<<d[i]<<" ";
 
  }

Measured memory_bytes: 5968
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

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

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

	if(a*b%2==0){
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}

	return 0;
}

Measured memory_bytes: 256