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

int main(){
    int n;  
    cin >> n;
    vector<int> lens(n);

    for(int i = 0; i < n; i++){
        cin >> lens.at(i);
    }

    sort(lens.begin(), lens.end());

    vector<int> origin_lens(n);
    origin_lens = lens;

    lens.erase(unique(lens.begin(), lens.end()), lens.end());

    vector<int> num(lens.size());

    for(int i = 0; i < lens.size(); i++){
        num.at(i) = count(origin_lens.begin(), origin_lens.end(), lens.at(i));
    }

    // for(int i = 0; i < lens.size(); i++){
    //     cout << num.at(i) << ", ";
    //     cout << lens.at(i) << endl;
    // }

    int count = 0;
    if(lens.size() < 3){
        cout << count << endl;
        return 0;
    }
    for(int i = 0; i < lens.size() - 2; i++){
        for(int j = i + 1; j < lens.size() - 1; j++){
            for(int k = j + 1; k < lens.size(); k++){
                if(abs(lens.at(i) - lens.at(j)) < lens.at(k) && lens.at(k) < lens.at(i) + lens.at(j)){
                    count += num.at(i) * num.at(j) * num.at(k);
                }
            }
        }
    }

    cout << count << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n;
  cin >> n;
  vi32 a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  sort(all(a));
  sort(all(b));
  sort(all(c));
  i64 ans = 0;
  rep(i, n) {
    i64 cnt1 = lower_bound(all(a), b[i]) - a.begin();
    i64 cnt2 = c.end() - upper_bound(all(c), b[i]);
    ans += cnt1 * cnt2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int digit(ll n){
    int cnt = 0;
    while(n>0){
        n/=10;
        cnt++;
    }
    return cnt;
}
int main(void){
    ll n; cin>>n;
    int ans = digit(n);
    for(ll A=1LL; A*A<= n; A++){
        if(n%A != 0) continue;
        ll b = n/A;
        ans = min(ans, max(digit(A), digit(b)));
    }
    cout<<ans<<endl;
}


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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >>D;
  if((A+B) > (C+D)){
    cout << "Left" << endl;
  }else if((A+B) <(C+D)){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;    
  }
}


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

const ll INF = 1LL << 60;

double A, B, C, D, E, F;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
    cin >> A >> B >> C >> D >> E >> F;

    double water_total = 0;  
    double sugar_total = 0;  
    double percent = 0;
    int max_v = F;

    for (int a = 0; a <= max_v; a += A * 100) {
        for (int b = 0; b <= max_v; b += B * 100) {
            for (int c = 0; c <= max_v; c += C) {
                for (int d = 0; d <= max_v; d += D) {
                    ll water = a + b;
                    ll sugar = c + d;
                    if (water + sugar > F) continue;

                    double tmp = (double)sugar / (sugar + water);
                    double max_rate = (double)E / (100 + E);
                    // if (max_rate < tmp) continue;

                    // cout << sugar << " " << (sugar + water) << endl;
                    // if (percent < tmp) {
                    if (percent <= tmp && tmp <= max_rate) {
                        water_total = water;
                        sugar_total = sugar;
                        percent = tmp; 
                    }
                }
            }
        }
    } 

    cout << water_total + sugar_total << " " << sugar_total << endl;
}

Measured memory_bytes: 3776
#[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")
        };
    }

fn main() {
    input! {
            l: i32,
            r: i32
        }

    #[allow(unused_assignments)]
    let mut ans = 0;

    if r - l >= 2019 {
        ans = 0;
    } else {
        let modded_values : Vec<i32> = (l..r+1).into_iter().map(|x| x % 2019).collect();
        ans = (0..modded_values.len()-1).into_iter().map(|i|
            (i+1..modded_values.len()).into_iter().map(|j|
                modded_values[i] * modded_values[j] % 2019
            ).fold(2019, |acc, x| if acc < x { acc } else { x })
        ).fold(2019, |acc, x| if acc < x { acc } else { x });
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3

output:
0 0
1 2
2 2
3 1
4 3
"""

import sys
import heapq as hp

WHITE, GRAY, BLACK = 0, 1, 2


class SingleSourceShortestPath(object):
    __slots__ = ('adj_table', 'distance', 'parent', 'visited')

    def __init__(self, in_data):
        v_num = int(in_data[0])
        vertices = map(lambda x: x.split(), in_data[1:])
        adj_table = tuple(dict() for _ in range(v_num))

        for v_info in vertices:
            source, v_adj_length, *v_adj_list = map(int, v_info)
            # assert len(v_adj_list) == v_adj_length * 2
            for target, cost in zip(v_adj_list[::2], v_adj_list[1::2]):
                adj_table[source][target] = cost

        self.adj_table = adj_table
        self.distance = [float('inf')] * v_num
        self.parent = [-1] * v_num
        self.visited = [WHITE] * v_num

    def path_heap_dijkstra(self, root):
        # path search init
        self.distance[root] = 0
        path_heap = list()
        # heapq: rank by tuple[0], at here it's d[u]
        hp.heappush(path_heap, (0, root))

        while path_heap:
            csp, current = hp.heappop(path_heap)
            self.visited[current] = BLACK

            for adj, cost in self.adj_table[current].items():
                if self.visited[adj] is not BLACK:
                    # alt: d[u] + w[u,v]
                    alt_path = self.distance[current] + cost
                    if alt_path < self.distance[adj]:
                        # update path_list
                        self.distance[adj] = alt_path
                        # update heap
                        hp.heappush(path_heap, (alt_path, adj))
                        self.visited[adj] = GRAY
                        self.parent[adj] = current

        return self.distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    case = SingleSourceShortestPath(in_data=_input)
    ans = case.path_heap_dijkstra(root=0)
    for i, v in enumerate(ans):
        print(i, v)

Measured memory_bytes: 63000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int A, B;
    cin >> A >> B;
    if(A < 10 && B < 10) {
        cout << A * B << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,k;
  cin >> n >> k;

  ll ans=0;
  for(ll b=k+1;b<=n;b++){
    ll a=n/b;
    ll c=n%b;
    ans+=(b-k)*a;
    if(c>=k)ans+=(c-k+1);
  }

  if(k!=0)cout << ans << endl;
  else cout << n*n << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M), AS(N+1), BS(M+1);
    rep(i,N){
        cin >> A[i];
    }
    ll sum = 0;
    rep(i,M){
        cin >> B[i];
        sum += B[i];
    }
    ll j = M-1;
    ll ans = 0;
    rep(i,N+1){
        while(j >= 0 && sum > K){
            sum -= B[j];
            j--;
        }
        if(sum <= K){
            cmax(ans, j+1+i);
        }
        if(i==N)break;
        sum += A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 9536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='?') s[i]='D';
	}
	cout<<s<<'\n';
}


Measured memory_bytes: 3744
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto AS = new int[][](3, 3);
    foreach (i; 0..3) foreach (j, a; readln.split.to!(int[])) AS[i][j] = a;
    auto N = readln.chomp.to!int;
    foreach (_; 0..N) {
        auto b = readln.chomp.to!int;
        foreach (i; 0..9) if (AS[i/3][i%3] == b) AS[i/3][i%3] = -1;
    }

    foreach (i; 0..3) {
        bool ok = true;
        foreach (j; 0..3) if (AS[i][j] != -1) ok = false;
        if (ok) {
            writeln("Yes");
            return;
        }
        ok = true;
        foreach (j; 0..3) if (AS[j][i] != -1) ok = false;
        if (ok) {
            writeln("Yes");
            return;
        }
    }

    if (
        (AS[0][0] == -1 && AS[1][1] == -1 && AS[2][2] == -1) ||
        (AS[0][2] == -1 && AS[1][1] == -1 && AS[2][0] == -1)
    ) {
        writeln("Yes");
        return;
    }

    writeln("No");
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, d int
	fmt.Scan(&n, &d)
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, d)
		for j := range x[i] {
			fmt.Scan(&x[i][j])
		}
	}

	cnt := 0
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			dist := 0
			for k := 0; k < d; k++ {
				dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
			}
			for l := 1; l <= 200; l++ {
				if dist == l*l {
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,k;
  string s;
  cin>>n>>k>>s;
  using P = pair<Int, Int>;
  deque<P> v;
  for(Int i=0;i<n;i++){
    if(v.empty()||v.back().first!=s[i]-'A')
      v.emplace_back(s[i]-'A',0);
    v.back().second++;
  }
  Int cnt=0,lst=0;
  while(!v.empty()&&v.back()==P(lst,1)){
    cnt++;
    lst^=1;
    v.pop_back();
  }

  Int t=0;
  auto print=[&](){
    for(Int i=0;i<(Int)v.size();i++)
      cout<<string(v[i].second,(t^v[i].first)+'A');
    Int x=lst;
    for(Int i=0;i<cnt;i++){
      x^=1;
      cout<<char('A'+x);
    }
    cout<<endl;
  };
  
  while(k){
    if(n%2==1&&cnt+1==n){
      v.pop_back();
      cnt++;
      lst^=1;
    }
    if(v.empty()) break;
    k--;
    if(v.front().first^t){
      if(!cnt &&(v.back().first^t)){
	v.back().second++;
      }else{
	cnt++;
	lst^=1;
      }
      if(!--v.front().second){
	v.pop_front();
      }
      t^=1;
    }else{
      if(!--v.front().second){
	v.pop_front();
	v.front().second++;
      }else v.emplace_front(t^1,1);      
    }
    //print();
  }
  //assert(n!=1);
  //cout<<k<<" "<<n<<endl;
  if((k&1)&&(n&1)){
    cout<<"B";
    cnt--;
    lst^=1;
  }
  print();
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  ll sum = 0, mx = -1;
  REP(i, n - 1) {
    ll diff = a[i + 1] - a[i];
    sum += diff;
    mx = max(mx, diff);
  }
  sum += a[0] + k - a[n - 1];
  mx = max(mx, a[0] + k - a[n - 1]);

  cout << sum - mx << endl;
  return 0;
}

Measured memory_bytes: 1792
n, k = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(k)]
p = list(map(int, input().split()))

r = 2 ** n
x = []
y = [[0 for i in range(k)]for i in range(r)]
z = 0

for i in range(r):
    x.append(str(bin(i).split('b')[1]).zfill(n))
    for j in range(k):
        for l in ks[j][1:]:
            y[i][j] += int(x[i][l - 1])
        if y[i][j] % 2 != p[j]:
            break
    else:
        z += 1

print(z)


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

namespace abc094_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(x[0] <= x[2] && x[2] <= x[0] + x[1] ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 11348
#include <stdio.h>

int main(){
  int A, B, K;
  scanf("%d %d",&A,&B);
  if((A+B) % 2 == 0){
  	if(A != B){
    	printf("%d\n", (A+B)>>1);
  	}else{
    	printf("0\n");
  	}
  }else{
    printf("IMPOSSIBLE\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int N = 2010;

vector<int> V[N];

int n, k;
bool f[N];
int Q[N], head, tail, dep[N], cnt, key;

void solve1(int x){
	head = tail = 0;
	Q[tail++] = x;

	cnt = 0;
	key = x;

	memset(dep, -1, sizeof(dep));
	dep[x] = 0;

    while(head < tail){
		x = Q[head++];
		if(dep[x] > dep[key]){
			key = x;
		}

		if(dep[x] > k){
			cnt++;
		}

		for(int i=0; i<V[x].size(); i++){
			int j = V[x][i];
			if(!f[j] && dep[j]==-1){
				dep[j] = dep[x] + 1;
				Q[tail++] = j;
			}
		}
    }
}

int solve(){
    int ret = 0;
    int key1, key2, cnt1, cnt2;
    bool flag;

    while(1){
		flag = 1;
    	for(int i=1; i<=n; i++){
			if(!f[i]){
				solve1(i);
				key1 = key;
				solve1(key1);
				cnt1 = cnt;
				key2 = key;

				if(dep[key2] <= k){
					flag = 0;
					break;
				}

				solve1(key2);
				cnt2 = cnt;

				if(cnt1 >= cnt2){
					f[key1] = 1;
				} else {
					f[key2] = 1;
				}

				break;
			}
    	}
    	if(!flag){
			break;
    	}
    	ret++;
    }

    return ret;
}

int main(){
	int x, y;
	while(~scanf("%d %d", &n, &k)){
		for(int i=1; i<=n; i++){
			V[i].clear();
			f[i] = 0;
		}
		for(int i=1; i<n; i++){
			scanf("%d %d", &x, &y);
			V[x].push_back(y);
			V[y].push_back(x);
		}
		if(k == n-1){
			puts("0");
		} else {
			printf("%d\n", solve());
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
map<pair<int,int>,int>m;
main(){
  int n,a,b,c,p=0;
  scanf("%d",&n);
  while(n--){
    scanf("%d%d%d",&a,&b,&c);
    r(i,2)r(j,2)
      p=max(p,m[make_pair(a+i,b+j)]+=c);
  }
  cout<<p<<" / 1"<<endl;      
}

Measured memory_bytes: 28204
import fractions
MOD = 1000000007

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


def get_lcm(a, b):
    return (a * b) // fractions.gcd(a, b)


x = A[0]
for a in A:
    x = get_lcm(a, x)


ret = 0
for a in A:
    ret += x // a

print(ret % MOD)


Measured memory_bytes: 6112
N, M = map(int, input().split())
K_A = [list(map(int, input().split())) for _ in range(N)]
result = [N] * M

for k_a in K_A:
    for a in k_a[1:]:
        result[a-1] -= 1

print(sum(map(lambda x: x == 0, result)))

Measured memory_bytes: 3060
#pragma warning(disable:4996)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;

int main()
{
	string s;
	int k;
	cin >> s;
	scanf("%d", &k);
	int len = s.length();
	long long ans = 0,cnt=1,cnt1=1,flag=0;
	s += '!';
	for (int i = 0; i < len; i++)
	{
		if (s[i] == s[i + 1])
		{
			cnt++;
			if (!flag)
			{
				cnt1++;
			}
		}
		else
		{
			ans += cnt / 2;
			flag = 1;
			if (i != len - 1)
			{
				cnt = 1;
			}
		}
	}
	if (cnt == len)
	{
		ans = 1ll*len*k/2;
	}
	else
	{
		ans *= k;
		if (cnt % 2 && cnt1 % 2 && s[0] == s[len - 1])
		{
			ans += k - 1;
		}
	}
	printf("%lld\n", ans);
	//system("pause");
	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,nn,nnn;
    cin>>n>>nn>>nnn;
    cout<<n+nn+nnn-max(n,max(nn,nnn));
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3000 + 10;
const ll mod = 998244353;
int a, b, c, d;
ll f[maxn][maxn];
int main()
{
	cin >> a >> b >> c >> d;
	for(int i = a; i <= c; ++i)
		for(int j = b; j <= d; ++j)
		{
			if(i == a && j == b) f[i][j] = 1;
			else
			{
				f[i][j] = f[i - 1][j] * j % mod + f[i][j - 1] * i % mod - f[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod;
				f[i][j] = (f[i][j] % mod + mod) % mod;
			}
		}
	cout << f[c][d] << endl;
	return 0;
}

Measured memory_bytes: 74084
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
#define dame {puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int n;
  cin>>n;
  map<int,int> m;
  rep(i,n){
    int a;
    cin>>a;
    m[a]++;
  }
  bool f;
  f = true;
  if(n%2==0){
    for(int i=1;i<n;i+=2) if(m[i]!=2){f=false;break;}
  }else{
    for(int i=2;i<n;i+=2) if(m[i]!=2){f=false;break;}
    if(m[0]!=1){f=false;}
  }
  if(f){
    ll ans=1;
    rep(i,n/2){
      ans*=2;
      if(ans>MOD) ans-=MOD;
    }
    cout<<ans<<endl;
  }else{
    cout<<0<<endl;
  }
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 3200
L, R = [int(i) for i in input().split(" ")]

flag=True
if (R - L) >= 2019:
  flag=False
  print(0)
else:
  min_mod = 2019
  for i in range(L, R):
    for j in range(i+1, R+1):
      tmp = (i*j) % 2019
      if tmp == 0:
        print(0)
        flag=False
        break
      elif tmp < min_mod:
        min_mod = tmp
    if flag==False:
      break

if flag==True:
  print(min_mod)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){

    int N;
    int a[10000];
    scanf("%d", &N);
    int count = 0;
    for(int i=0; i<N; i++){
        scanf("%d", &a[i]);
        while(a[i] % 2 == 0){
            a[i] = a[i] / 2;
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,a,b,c,d,count=0;
	while(scanf("%d",&n)!=EOF){
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(n==a+b+c+d){count++;}
					}
				}
			}
		}
		printf("%d\n",count);
		count=0;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a>9||b>9) cout << -1 << endl;
    else cout << a*b << endl;
}

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

int main(){
	int N,K,ans=0;
	cin >> N >> K;
	vector <int> l(N);
	for(int i=0;i<N;i++){
		cin >> l[i];
	}
	sort(l.rbegin(),l.rend());
	for(int i=0;i<K;i++){
		ans+=l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

void solve(){
    int a,b;
    cin>>a>>b;
    if(a<10&&b<10)cout<<a*b<<"\n";
    else cout<<-1<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	//cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

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

T = 1
A = 1
for _ in range(n):
    t, a = map(int, input().split())
    m = max([T // t, A // a])
    for i in range(1000):
        i += m
        if T <= t * i and A <= a * i:
            T = t * i
            A = a * i
            break

print(A + T)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	int n; cin >> n;
	vector<string> s(n);
	rep(i, n)cin >> s[i];
	int ABin = 0, swB = 0, ewA = 0, both = 0;
	rep(i, n)
	{
		int k = sz(s[i]);
		if (s[i][0] == 'B') ++swB;
		if (s[i][k - 1] == 'A') ++ewA;
		if (s[i][0] == 'B' && s[i][k - 1] == 'A') ++both;
		rep(j, k - 1)
		{
			if (s[i][j] == 'A' && s[i][j + 1] == 'B')++ABin;
		}
	}
	swB -= both;
	ewA -= both;
	int ans = ABin;
	if (!both)ans += min(swB, ewA);
	else if (swB && ewA)
	{
		ans += both + 1;
		ans += min(swB - 1, ewA - 1);
	}
	else if(!swB && !ewA)
	{
		ans += both-1;
	}
	else
	{
		ans += both;
	}
	co(ans);
	return 0;
}


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

vector<int> v(303030);
ll n,k,m,x,y,a;
string s,t;
bool dp[101010];

int main() {
  cin >> n;
  int cnt=0;
  rep(i,n){
  cin >> a;
  if(!(a&1)) cnt++;
  }
  cout << pow(3,n)-pow(2,cnt) << endl;
}

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

int main()
{
    std::string s;
    long long k,n;
    std::cin >> s >> k;
    n = s.size();
    std::vector<std::vector<std::vector<long long>>> dp(n + 10,std::vector<std::vector<long long>>(200,std::vector<long long>(2)));
    dp[0][0][0] = 1;

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

        for(long long j = 0; j < 110; j++){

            for(long long t = 0; t < 2; t++){

                long long lim = (t ? 9 : s[i] - '0');
                for(long long d = 0; d <= lim; d++){
                    dp[i + 1][j + (d != 0)][t || d < lim] += dp[i][j][t];
                }
            }
        }
    }
    std::cout << dp[n][k][0] + dp[n][k][1] << std::endl;

}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,e,f,s;
	scanf("%d",&n);
	for (a=0;a<n;a++)
	{
		scanf("%d %d %d %d",&b,&c,&d,&e);
		f=b*d+c*e;
		if (d>=5&&e>=2)
		{
			f=f*0.8;
			printf("%d\n",f);
		}
		else
		{
			if(d<5)
			d=5;
			if(e<2)
			e=2;
			s=(b*d+c*e)*0.8;
			if(s<f)
			f=s;
		printf("%d\n",f);
		}
	}
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int main()
{
	int i;

	string s;
	cin >>s;

	string ans="";
	int ct=0;
	rep(i,s.size())
	{
		if((ct%2==0 && s[i]=='A')||(ct%2==1 && s[i]=='Z'))
		{
			ans+=s[i];
			++ct;
		}
	}

	if(ans.size()<2) ans="-1";
	else if(ans.size()%2==1) ans.resize(ans.size()-1);
	std::cout << ans << std::endl;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    auto a = make_vec<char>(H, W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> a[i][j];
        }
    }

    vector<vector<char>> b;
    for (int i = 0; i < H; i++) {
        bool flag = false;
        for (int j = 0; j < W; j++) {
            if (a[i][j] == '#') {
                flag = true;
                break;
            }
        }
        if (flag) {
            b.push_back(a[i]);
        }
    }
    H = (int)b.size();
    vector<int> p;
    for (int j = 0; j < W; j++) {
        bool flag = false;
        for (int i = 0; i < H; i++) {
            if (b[i][j] == '#') {
                flag = true;
                break;
            }
        }
        if (flag) {
            p.push_back(j);
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < (int)p.size(); j++) {
            cout << b[i][p[j]];
        }
        cout << "\n";
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;

  REP(i,100){
    if (n!=0){
      ans++;
    }else{
      break;
    }
    n/=k;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import copy
def solve(ans):
  answers = []
  temp = copy.deepcopy(ans)
  flag = 1
  for i in range(len(ans)):
    ans[i] *= flag
    flag *= -1
  
  func = lambda x,y: x-y

  answers.append(sum(ans))

  for i in range(len(ans)-1):
    answers.append(int(2*func(temp[i], answers[i]/2)))
  return answers

n = int(input())

dam = [int(i) for i in input().split()]

print(*solve(dam))

Measured memory_bytes: 15876
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	for (int i = 0; i < N; ++i) {
		cin >> s[i];
	}
	bool ok = true;
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < i; ++j) {
			if (s[i] == s[j]) ok = false;
		}
		if (s[i - 1].back() != s[i].front()) ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

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

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

    vector<pair<string, lint>> tunes(n);
    for(lint i=0; i<n; i++) {
        cin >> tunes[i].first >> tunes[i].second;
    }

    string x;
    cin >> x;

    bool after = false;
    lint ans = 0;
    for(lint i=0; i<n; i++) {
        if(after)  ans += tunes[i].second;
        if(tunes[i].first == x)  after = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 764
N,Y=map(int,input().split())
ans=0
for i in range(max(N,Y//10000)+1):
    if ans==1:
        break
    for k in range(max(N-i,(Y-10000*i)//5000)+1):
        if 10000*i+5000*k+1000*(N-i-k)==Y:
            print(i,k,N-i-k)
            ans=1
if ans==0:
    print(-1,-1,-1)

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

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, H) { cin >> a[i]; }
    for (ll i = H - 1; i >= 0; i--) {
        if (a[i].find('#') == a[i].npos) {
            a.erase(a.begin() + i);
        }
    }
    for (ll i = W - 1; i >= 0; i--) {
        ll cnt = 0;
        rep(j, a.size()) {
            if (a[j][i] == '.') cnt++;
        }
        if (cnt == a.size()) {
            rep(j, a.size()) { a[j].erase(i, 1); }
        }
    }

    rep(i, a.size()) { cout << a[i] << endl; }

    return 0;
}


Measured memory_bytes: 256
import operator as op
from functools import reduce

def comb(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
n,m = map(int, input(). split())
A = 0
B = 0
if n >= 2:
  A = int(comb(n, 2))
if m >= 2:
  B = int(comb(m, 2))
print(A + B)

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

using namespace std;

int N, X, T;

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

	// T分毎にX個
	// N個のたこ焼きを作る
	// takoyaki>=N になるまで続けたら、timeが答え

	int takoyaki = 0;
	int time = 0;

	while (takoyaki < N) {
		time += T;
		takoyaki += X;
	}

	cout << time << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <map>

using namespace std;

int main(){
    int N;
    cin >> N;
    int D[N];
    map <int, int> m;

    for (int i = 0; i < N; i++){
        cin >> D[i];
        m[D[i]] ++;
    }
    
    int M;
    cin >> M;
    int T[M];
    bool flag = true;
    for (int i = 0; i < M; i++){
        cin >> T[i];
        m[T[i]] --;
        if (m[T[i]] < 0){
            flag = false;
        }
    }
    
    if (flag == true){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int q;
  cin >> q;
  rep(qi, q)
  {
    int type;
    cin >> type;
    if (type == 0)
    {
      int b, e;
      cin >> b >> e;
      ll Min = *min_element(a.begin() + b, a.begin() + e);
      cout << Min << endl;
    }
    else
    {
      int b, e;
      cin >> b >> e;
      ll Max = *max_element(a.begin() + b, a.begin() + e);
      cout << Max << endl;
    }
  }

  return 0;
}



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

int main() {

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


  int n, m;
  cin >> n >> m;

  set<int> s;
  for (int i = 0; i < m; ++i) {
    int d;
    cin >> d;

    for (int j = 0, x; j < d; ++j) {
      cin >> x;
      s.insert(x);
    }
  }

  cout << n - (int)s.size() << '\n';
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	string str;
	cin>>str;
	int count0=0,count1=0;
	for(int i=0;i<(int)str.size();i++){
		char ch = str[i];
		int temp = ch - '0';
		if(temp==1)count1+=1;
		else count0+=1;
	}
	if(count0>=count1)cout<<count1*2<<endl;
	else cout<<count0*2<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int o=0;
	int n;
	string s;
	int b,c;
	cin>>n>>b>>c;
	if(n+b>=c){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
}
//伊勢田=sanadayukimura"73"
//伊勢田=48
//73=48
//両方から23を引いて
//50=25
//2=1


Measured memory_bytes: 256
#include <iostream>

int calcDigit(int N, int K, int d) {
    if(N < K) {
        return d+1;
    } else {
        return calcDigit(N/K, K, d+1);
    }
}

int main(int argc, const char * argv[]) {
    int N(0), K(0);

    std::cin >> N >> K;

    int digit = calcDigit(N, K, 0);

    std::cout << digit;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;

bool is_prime(int a) {
	for(int i = 2; i * i <= a; i++) {
		if(a % i == 0) return false;
	}
	return true;
}

void solve() {
	cin >> N;
	ll ans = 1;
	rep(i, 2, N + 1) {
		if(!is_prime(i)) continue;
		int p = 1;
		rep(j, 2, N + 1) {
			int n = j;
			while(n % i == 0) {
				n /= i;
				p++;
			}
		}
		MUL(ans, p);
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1), a(n);
    for (int i = 0; i < n - 1; i++) {
        cin >> b[i];
    }

    a[0] = b[0];
    for (int i = 1; i < n - 1; i++) {
        a[i] = min(b[i - 1], b[i]);
    }
    a[n - 1] = b[n - 2];

    int ans = accumulate(a.begin(), a.end(), 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    int A=0,B=0,C=0,D=0;
    rep(i,N){
        string s;
        cin>>s;
        if(s=="AC"){A++;}
        else if(s=="WA"){B++;}
        else if(s=="TLE"){C++;}
        else{D++;}
    }
    cout<<"AC"<<" x "<<A<<endl;
    cout<<"WA"<<" x "<<B<<endl;
    cout<<"TLE"<<" x "<<C<<endl;
    cout<<"RE"<<" x "<<D<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,d,x[10][10],ans=0;
  cin >> n >> d;
  double cnt;
  for(int i=0; i<n; i++) {
    for(int j=0; j<d; j++) {
      cin >> x[i][j];
    }
  }
  for(int i=0; i<n-1; i++) {
    for(int j=i+1; j<n; j++) {
      cnt=0;
      for(int k=0; k<d; k++) {
        cnt+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      cnt=sqrt(cnt);
      if(cnt-floor(cnt)==0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 764
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int r = stdIn.nextInt();
        if(n >= 10) System.out.println(r);
        else System.out.println(r + 100*(10-n)) ;
    }
}

Measured memory_bytes: 22228
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,t,i,z,k;
    int a[100010];
    while(scanf("%d",&n)!=EOF){
        t=1;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        z=a[1];
        for(i=1;i<n;i++){
            if(z!=2){
                z=a[z];
                t++;
            }
            else {printf("%d\n",t);break;}
        }
        if(i==n)printf("-1\n");

    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


int main(){
    int n; cin >> n;
    int a[n];
    
    rep(i,n) cin >> a[i];
    
    map<int,int> m;
    
    rep(i,n){
        m[a[i]]++;
    }
    
    int ans = 0;
    for(auto p: m){
        int x = p.first;
        int n = p.second;
        
        if(n<x) ans += n;
        else ans += n-x;
    }
    
    cout << ans << endl;
    
}



Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int L;
int dig(int x) {
	int ret = 0;
	while (x > 0) {
		x /= 2;
		ret++;
	}
	return ret;
}

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

	cin >> L;
	if (L == 2) {
		cout << 2 << " " << 2 << endl;
		cout << 1 << " " << 2 << " " << 0 << endl;
		cout << 1 << " " << 2 << " " << 1 << endl;
		return 0;
	}
	L--;
	int N = dig(L);

	vector<vector<int>>E;
	for (int i = 1; i <= N - 1; i++){
		E.pb({i,i+1,0});
		E.pb({i,i+1,1 << (N-1-i)});
	}


	int cur = (1 << (N - 1));
	for (int i = N-2; i >= 0; i--) {
		if ((1 << i) & L) {
			E.pb({1,N-i,cur});
			cur += (1 << i);
		}
	}
	E.pb({1,N,L});

	int M = E.size();
	cout << N << " " << M << endl;
	fore(x, E)cout << x[0] << " " << x[1] << " " << x[2] << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		int per = d*2+1;
		
		int ans = (n%per == 0) ? n/per : n/per+1;
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 23892
n = gets.to_i
a = []
n.times do 
  b = [gets.chomp, 1]
  frag = false
  a.length.times do |i|
    if a[i][0] == b[0]
      a[i][1] += 1
      frag = true
    end
  end
  if frag == false
    a.push(b)
  end
end
m = gets.to_i
m.times do 
  b = [gets.chomp, -1]
  frag = false
  a.length.times do |j|
    if a[j][0] == b[0]
      a[j][1] -= 1
      frag = true
    end
  end
  if frag == false
    a.push(b)
  end
end
max = 0
a.length.times do |l|
  if a[l][1] > max 
    max = a[l][1]
  end
end
puts max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b))cout<<"B"<<endl;
    else cout<<"A"<<endl;
}


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

int n, W;
const int maxn = 105;
int w[maxn], v[maxn];
int dp[2][105][305];

void solve(){

}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> W;
    for(int i = 1;i <= n;i++){
        cin >> w[i] >> v[i];
    } 
    memset(dp, -1, sizeof(dp));
    dp[0][0][0] = 0;
    for(int i = 1;i <= n;i++){
        int cur = i & 1;
        int pre = cur ^ 1;
        memset(dp[cur], -1, sizeof(dp[cur]));
        for(int j = 0;j <= i;j++){
            for(int k = 0;k <= 3 * i;k++){
                if(dp[pre][j][k] != -1){
                    dp[cur][j][k] = max(dp[cur][j][k], dp[pre][j][k]);
                    dp[cur][j + 1][k + w[i] - w[1]] = max(dp[cur][j + 1][k + w[i] - w[1]], dp[pre][j][k] + v[i]);
                }
            }
        }
    }
    int cur = n & 1;
    int ans = 0;
    for(int j = 0;j <= n;j++){
        for(int k = 0;k <= 3 * n;k++){
            if(dp[cur][j][k] != -1){
                long long weight = 1LL * j * w[1] + k;
                if(weight <= W){
                    ans = max(ans, dp[cur][j][k]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#define lli long long int

lli patty[55], panjang[55];

lli dp(lli en, lli ex) {
	if (ex == 0)
		return 0;
	if (ex >= (panjang[en] - en))
		return patty[en];
	if (ex > (panjang[en - 1] + 1))
		return (patty[en - 1] + 1 + dp(en - 1, ex - (panjang[en - 1] + 2)));
	return dp(en - 1, ex - 1);
}

int main() {
	lli n, x, ans;
	scanf("%lld %lld", &n, &x);
	patty[0] = 1;
	panjang[0] = 1;
	for (lli i = 1; i < 51; i++) {
		patty[i] = (2 * patty[i - 1]) + 1;
		panjang[i] = (2 * panjang[i - 1]) + 3;
	}
	ans = dp(n, x);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128