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

#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()

const int N = 1e5;
vector <int> G[N + 7];
vector <int> T[N + 7];
int n;

int dp[N + 7][2];
bool moze[N + 7];

void dfs0(int v, int p) {
  for (auto u : G[v]) {
    if (u != p) {
      T[v].push_back(u);
      dfs0(u, v);
    }
  }
  
  if (T[v].empty()) moze[v] = 1;
  else if (SZ(T[v]) == 1) {
    moze[v] = moze[T[v].back()];
  }
  else moze[v] = 0;
}

int wynik = 0;

void dfs1(int v, int p) {
  if (SZ(T[v]) == 1) {
    dfs1(T[v].back(), v);
    return;
  }
  else if (T[v].empty()) {
    wynik++;
    return;
  }
  else {
    int tu = 0;
    for (auto u : T[v]) if (moze[u]) tu = u;
    for (auto u : T[v]) if (u != tu) dfs1(u, v);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    G[a + 1].push_back(b + 1);
    G[b + 1].push_back(a + 1);
  }

  int s = 0;
  for (int i = 1; i <= n; ++i) if (SZ(G[i]) > 2) s = i; 

  if (s == 0) {
    cout << 1 << endl;
    return 0;
  }
  
  dfs0(s, 0);
  dfs1(s, 0);
  
  cout << wynik << endl;
  return 0;
}

Measured memory_bytes: 16128
def main():
    A = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    B = [int(input()) for _ in range(n)]
    ans =  [None]*8
    AT = list(zip(*A))
    ans[0] = set(A[0])
    ans[1] = set(A[1])
    ans[2] = set(A[2])
    ans[3] = set(AT[0])
    ans[4] = set(AT[1])
    ans[5] = set(AT[2])
    ans[6] = set([A[i][i] for i in range(3)])
    ans[7] = set([A[i][2-i] for i in range(3)])

    for b in B:
        for a in ans:
            if b in a:
                a -= {b}
                if not a:
                    print("Yes")
                    return
    print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

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

    def roots(self):
        return [i for i, x in enumerate(self.parents) 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 __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m=map(int,input().split())
p=list(map(int,input().split()))
uf=UnionFind(n)
for i in range(m):
    x,y=map(int,input().split())
    uf.union(x-1,y-1)

ans=0
for i in range(n):
    if uf.same(i,p[i]-1):
        ans+=1
print(ans)

Measured memory_bytes: 89068
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;cin >> n >> k;
  string s; cin >> s;
  if(s[k-1] == 'A') s[k-1] = 'a';
  if(s[k-1] == 'B') s[k-1] = 'b';
  if(s[k-1] == 'C') s[k-1] = 'c';
  cout << s << endl;
}
  

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;

signed main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    --A;
    --B;
    --C;
    --D;
    string S;
    cin >> S;
    bool check = true;
    if (C < D) {
        for (int i = B; i < D;) {
            if (S[i + 1] == '.') ++i;
            else if (i != N - 1 && S[i + 1] == '#' && S[i + 2] == '.') i += 2;
            else {
                check = false;
                break;
            }
        }
        for (int i = A; i < C;) {
            if (S[i + 1] == '.') ++i;
            else if (i != N - 1 && S[i + 1] == '#' && S[i + 2] == '.') i += 2;
            else {
                check = false;
                break;
            }
        }
    } else if (C > D) {
        bool ABswitch = false;
        vector<int> coordinate;
        for (int i = B - 1; i <= min(D - 1, C - 2); i++) {
            if (S.substr(i, 3) == "...") {
                coordinate.push_back(i);
                ABswitch = true;
                break;
            }
        }
        if (!ABswitch) check = false;
        if (check) {
            for (int i = B; i < D;) {
                if (S[i + 1] == '.') ++i;
                else if (i != N - 1 && S[i + 1] == '#' && S[i + 2] == '.') i += 2;
                else {
                    check = false;
                    break;
                }
            }
            for (int i = A; i < C;) {
                if (S[i + 1] == '.') ++i;
                else if (i != N - 1 && S[i + 1] == '#' && S[i + 2] == '.') i += 2;
                else {
                    check = false;
                    break;
                }
            }
        }
    }


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


Measured memory_bytes: 640
import collections

n, *s_n = open(0).read().split()
n = int(n)

dic = collections.Counter(s_n)

dic_values_max = max(list(dic.values()))

max_key = [i for i, j in dic.items() if j == dic_values_max]

max_key.sort()

for k in max_key:
    print(k)

Measured memory_bytes: 38392
#include<stdio.h>

int main(){

	int a, b, i, ans;
	int keta = 0;
//	int c = 200;	//?????§200???

	//??´??°a,b?????????????????????????????????
	
	while(scanf("%d %d",&a ,&b) != EOF){
			//a,b???????????????0??\???100000??\??????????????????????????\??????break???
			if(!((a >= 0) && (a <= 1000000)) && ((b >= 0) && (b <= 1000000))){	
				while( getchar() != '\n' );	
				break;
			}
		
		keta=0;
		ans= a + b;
		//?????°????¨????????????????
		while(ans != 0){
		ans = ans /10;
		++keta;
		}
		//??°???????????°?????¨???????????????
		printf("%d\n",keta);
//		c--;
	}
	
    return 0;
}

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

using namespace std;

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    if(a*a*b/2 < x){
        cout << setprecision(12) << ((double)90*(double)2/M_PI)*atan((2*(a*a*b-x))/(a*a*a));
    }else{
        cout << setprecision(12) << ((double)90*(double)2/M_PI)*atan((a*b*b)/(2*x));
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
 
typedef signed long long ll;
const int MX = 1e6 + 5;

int main() {
	int n, num, j = 1, cnt = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &num);
		if(num == j) {
			j++; cnt++;
		}
	}

	(cnt == 0) ? printf("-1\n") : printf("%d\n", n - cnt);
	
    return 0;
}

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

#define BR "\n"
#define SP " "

ll n, k;
ll MOD = 1e9+7;

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

  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans = (ans * (k -i)) % MOD;
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3108
def get_ints():
  return list(map(int,input().split()))

n = int(input())
a = get_ints()
b = get_ints()

cnt = [0]*(n+1)
for x in a+b:
  cnt[x] += 1

q = [set() for i in range(n+1)]
for i in range(1,n+1):
  if cnt[i] > n:
    print('No')
    exit(0)
  q[cnt[i]].add(i)
print('Yes')

def make_cnt(a):
  cnt_ = {}
  for i in range(n):
    if a[i] not in cnt_:
      cnt_[a[i]] = [i]
    else:
      cnt_[a[i]].append(i)
  return cnt_

cnt_a = make_cnt(a)
cnt_b = make_cnt(b)

def get_any(cnt_, x):
  for key in cnt_.keys():
    if key != x:
      return key
  assert False

ans = [-1]*n

for i in range(n,0,-1):
  s = list(q[i])
  x,y = 0,0
  if len(s) == 0:
    x = get_any(cnt_a, -1)
    y = get_any(cnt_b, x)
  elif len(s) == 1:
    x = s[0]
    if x not in cnt_a: # b kara
      y = x
      x = get_any(cnt_a, y)
    else: # a kara
      y = get_any(cnt_b, x)
  else: # 2
    x,y = s
    if x not in cnt_a:
      x,y = y,x

  ans[cnt_a[x][-1]] = y
  def update_cnt(cnt_, x):
    cnt_[x].pop()
    if len(cnt_[x]) == 0:
      del cnt_[x]
  def use(x):
    q[cnt[x]].remove(x)
    cnt[x] -= 1
    q[cnt[x]].add(x)
  update_cnt(cnt_a, x)
  update_cnt(cnt_b, y)
  use(x)
  use(y)

print(' '.join(map(str,ans)))

Measured memory_bytes: 189208
#include <stdio.h>
#include <string.h>

int main(){
    char a[105];
    scanf("%s", a);
    char b = ' ';

    for(int i=0; i < strlen(a); i++){
        if(a[i]== ','){
            a[i] = b;
        }
    }
    printf("%s", a);
    return 0;
}

Measured memory_bytes: 1724
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
 
using namespace std;
 
int main(void){
  int N;
  cin >> N;

  int tmp, TOTAL = 0;
  vector<int> SUM;
  for(int i=0; i<N; i++){
	cin >> tmp;
    TOTAL += tmp;
    SUM.push_back(TOTAL);
  }

  int min_sum = TOTAL;
  for(int i=0; i<N-1; i++){
    tmp = abs(TOTAL - 2*SUM[i]);
    min_sum = min(min_sum, tmp);
  }
  
  cout << min_sum << endl;
  
  return 0;
}

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 300005
using namespace std;

int main()
{
    FLASH
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(all(a));
    reverse(all(a));
    if(n == 2){
        cout << a[0] ;
        return 0;   
    }
    ll ans = 0;
    ans = a[0] + a[1];
    priority_queue<pair<ll,pair<ll,ll> > > pq;
    pq.push({a[1],{a[0],a[1]}});
    pq.push({a[2],{a[1],a[2]}});
    pq.push({a[2],{a[2],a[0]}});
    for(int i = 3; i < n; i++){
        auto p = pq.top();
        pq.pop();
        ans += p.first;
        pq.push({ min(p.second.first,a[i])  ,{p.second.first,a[i]}});
        pq.push({ min(p.second.second,a[i])  ,{p.second.second,a[i]}});
    } 
    cout << ans << '\n' ;
    return 0;
}


Measured memory_bytes: 11064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll N, ans;
ll a[200000];
ll l[200000];
ll r[200000];

signed main() {
  cin >> N;
  rep(i, N + 1)
    cin >> a[i];
  l[N] = r[N] = a[N];
  for (ll i = N - 1; i >= 0; i--) {
    l[i] = (l[i + 1] + 1)/ 2 + a[i];
    r[i] = r[i + 1] + a[i];
  }
  if (1 < l[0] || r[0] < 1) {
    cout << -1 << endl;
    return 0;
  }
  ll node = 1;
  for (ll i = 0; i <= N; i++) {
    node = min(node, r[i]);
    ans += node;
    node -= a[i];
    node *= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5944
import scala.io.StdIn._

object Main  {
  def main(args: Array[String]): Unit = {
    val _ = readLine
    println(solve(readLine.split(" ")))
  }

  def solve(nums: Array[String]): String = {
    if (nums.length == nums.toSet.size) {
      "YES"
    } else {
      "NO"
    }
  }
}

Measured memory_bytes: 103768
while 1:
	a, op, b = input().split()
	a = int(a)
	b = int(b)

	if op == '?': break
	if op == '+': print(a + b)
	if op == '-': print(a - b)
	if op == '*': print(a * b)
	if op == '/': print(a // b)

Measured memory_bytes: 7600
#include <bits/stdc++.h>
using namespace std; 
int main(){
  string s;
  int i;
  cin >> s;
  int mini=753;
  for(i=0;i<s.size()-2;i++){
    int sum=0;
    sum=(s.at(i)-'0')*100+(s.at(i+1)-'0')*10+s.at(i+2)-'0';
    mini=min(mini,abs(sum-753));
  }
  cout << mini;
}

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

using namespace std;

#define INF 10000

int main(void)
{
	int n, l;
	cin >> n >> l;
	int sum = 0;
	int ans = 0;
	int sub = INF;
	for (int i = l; i < l + n; ++i)
	{
		sum += i;
	}
	for (int i = l; i < l + n; ++i)
	{
		int bufn, bufn1;
		bufn = sum, bufn1 = sum - i;
		if (abs(bufn - bufn1) < sub)
		{
			sub = abs(bufn - bufn1);
			ans = bufn1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

h, w, m = map(int, input().split())
beds = [tuple(map(lambda x: int(x) - 1, input().split()))  for _ in range(m)]

bom_v = Counter(b[0] for b in beds)
bom_h = Counter(b[1] for b in beds)

v_max = max(bom_v.values())
h_max = max(bom_h.values())

cand = list(bom_v.values()).count(v_max) * list(bom_h.values()).count(h_max)
bombs = len([... for i, j in beds if bom_v[i] ==  v_max and bom_h[j] ==  h_max])

if cand - bombs > 0:
    print(v_max + h_max)
else:
    print(v_max + h_max - 1)

Measured memory_bytes: 80380
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rep1(i,n) for (int i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
int main(){
  ll a; cin >> a;
  cout << a+a*a+a*a*a;
  return 0;
}


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

int main() {
    int N, A[1000], i, j, change;
    
    cin >> N;
    
    for (i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    for (i = 0; i < N-1; i++) {
        for (j = i; j < N; j++) {
            if (A[j] < A[i]) {
                change = A[i];
                A[i] = A[j];
                A[j] = change;
            }
        }
    }
    
    cout << abs(A[0] - A[N-1]);
    cout << "\n";
    
    return 0;
}

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

long long a, b, q;
vector<long long> s, t;
long long x[100005] = {0};

long long solve(long long x);

int main() {
  cin >> a >> b >> q;
  for(int i = 0; i < a; ++i) {
    long long c;
    cin >> c;
    s.push_back(c);
  }
  for(int i = 0; i < b; ++i) {
    long long c;
    cin >> c;
    t.push_back(c);
  }
  for(int i = 0; i < q; ++i) cin >> x[i];
  for(int i = 0; i < q; ++i) cout << solve(x[i]) << endl;
  return 0;
}

long long solve(long long x) {
  long long ans = 100000000000000000;
  auto its = lower_bound(s.begin(), s.end(), x);
  auto itt = lower_bound(t.begin(), t.end(), x);
  // l l
  if(its != s.begin() && itt != t.begin()) {
    --its;
    --itt;
    ans = min(ans, x - min(*itt, *its));
    ++its;
    ++itt;
  }
  if(its != s.begin() && itt != t.end()) {
    --its;
    ans = min(ans, *itt - *its + min(x - *its, *itt - x));
    ++its;
  }
  if(its != s.end() && itt != t.begin()) {
    --itt;
    ans = min(ans, *its - *itt + min(x - *itt, *its - x));
    ++itt;
  }
  if(its != s.end() && itt != t.end()) {
    ans = min(ans, max(*itt, *its) - x);
  }
  return ans;
}

Measured memory_bytes: 3828
#include <iostream>

using namespace std;

int main()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int A[n],H[n+1];
for(int i=0;i<=n+1;i++)
{
    H[i]=0;
}
for(int i=1;i<n;i++)
{   cin>>A[i];
    H[A[i]]++;
}
for(int i=1;i<=n;i++)
{
    cout<<H[i]<<"\n";
}

    return 0;
}


Measured memory_bytes: 5216
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, d := io.NextInt(), io.NextFloat()
	cnt := 0
	for i := 0; i < n; i++ {
		xi, yi := io.NextFloat(), io.NextFloat()
		dist := math.Sqrt(xi*xi + yi*yi)
		if dist <= d {
			cnt++
		}
	}
	io.Println(cnt)
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextFloat returns a float64 number from stdin
func (io *Io) NextFloat() float64 {
	f, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

using namespace std;

#ifdef LOCAL
  #include "debug.h"
#else
  #define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = (int) s.size();
  int m = (int) t.size();
  int ans = m;
  
  auto get = [&](string& a, string& b) {
    int ret = 0;
    for (int i = 0; i < (int) a.size(); i++) {
      ret += a[i] != b[i];
    }
    return ret;
  };
  for (int i = 0; i < n - m + 1; i++) {
    string sub = s.substr(i, m);
    ans = min(ans, get(sub, t));
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector<int> m(5);

    for(int i=0; i<5; i++){
        cin >> m[i];
    }
    sort(m.begin(), m.end(), greater<int>());

    for(int i=0; i<5; i++){
        if(i) cout << " ";
        cout << m[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int count = 0;
	for (int i = a; i < b + 1; i++) {
		if (c % i == 0) {
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}



Measured memory_bytes: 2096
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
from itertools import accumulate

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

sushi = defaultdict(list)

for i in range(N):
    t, d = map(int, input().split())
    sushi[t].append(d)

first = []
second = []
for key in sushi:
    sushi[key].sort(reverse=True)
    first.append(sushi[key][0])
    second += sushi[key][1:]

first.sort(reverse=True)
second.sort(reverse=True)

first_cum = [0] + list(accumulate(first))
second_cum = [0] + list(accumulate(second))


ans = 0
for i in range(1, K+1):
    if K - i <= len(second_cum)-1 and i <= len(first_cum)-1:
        ans = max(ans, first_cum[i] + second_cum[K-i] + i*i)

print(ans)

Measured memory_bytes: 69212
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n+1-h)*(n+1-w) << endl;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input =new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = input.readLine().split(" ");
        long A = Long.parseLong(inputs[0]);
        long B = Long.parseLong(inputs[1]);
        long C = Long.parseLong(inputs[2]);
        long D = Long.parseLong(inputs[3]);

        System.out.println(Math.max(A*B,C*D));
    }
}

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

#define ll long long
#define ld long double

#define all(x) x.begin(),x.end()

using namespace std;

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

	ll a,b,x;
	cin>>a>>b>>x;
	
	ll r;
	
	r = b/x;
	r++;
	
	if (a) r-= (a-1)/x + 1;
	
	cout<<r;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int s[4];
int a[4];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<4;i++){
		a[i]=n%10;
		n/=10;
	}
	for(int i=0;i<4;i++){
		s[i]=a[3-i];
	}
	if(s[0]+s[1]+s[2]+s[3]==7){ printf("%d+%d+%d+%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]+s[1]+s[2]-s[3]==7) {printf("%d+%d+%d-%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]+s[1]-s[2]+s[3]==7) {printf("%d+%d-%d+%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]+s[1]-s[2]-s[3]==7) {printf("%d+%d-%d-%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]-s[1]+s[2]+s[3]==7) {printf("%d-%d+%d+%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]-s[1]+s[2]-s[3]==7) {printf("%d-%d+%d-%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]-s[1]-s[2]+s[3]==7) {printf("%d-%d-%d+%d=7",s[0],s[1],s[2],s[3]);return 0;}
	if(s[0]-s[1]-s[2]-s[3]==7) {printf("%d-%d-%d-%d=7",s[0],s[1],s[2],s[3]);return 0;}


}


Measured memory_bytes: 128
ARGF.each do |line|
  break if line =~ /^0$/
  points = gets.split.map(&:to_f)

  avg = points.inject(:+) / points.size

  a = points.inject(0){|ret, p| ret + (p - avg)**2 / points.size }
  
  puts Math.sqrt(a)
end

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

using namespace std;

int main() {
	int d, n;
	cin >> d >> n;

	int k = pow(100, d);

	if (n == 100) {
		cout << k * (n + 1) << endl;
	}
	else {
		cout << k * n << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int res = 0;
  for (int i=0 ; i<N ; i++) {
    int num;
    scanf("%d", &num);
    res += num - 1;
  }
  printf("%d\n", res);
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  char c;
  cin >> c;
  if(c=='A')
    cout << "T" << endl;
  else if(c=='T')
    cout << 'A' << endl;
  else if(c=='C')
    cout << 'G' << endl;
  else
    cout << 'C' << endl;
}


Measured memory_bytes: 256
N, Y = list(map(int, input().split(' ')))

# N枚、Y円の条件を満たす組み合わせ
# [1万円札, 5千円札, 千円札]
goodBills = [-1, -1, -1]
foundGoodBills = False

# 1万円札、5千円札でループ
for i10k in range(N + 1):
    for i5k in range(N + 1 - i10k):
        i1k = N - i10k - i5k
        money = 10000 * i10k + 5000 * i5k + 1000 * i1k

        # 条件を満たす組み合わせ
        if 0 <= i1k <= N and money == Y:
            goodBills = [i10k, i5k, i1k]
            foundGoodBills = True
            break

        if foundGoodBills:
            break

    if foundGoodBills:
        break

print(' '.join(map(str, goodBills)))


Measured memory_bytes: 9224
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll A, B;

int main() {
	scanf("%lld %lld", &A, &B);
	if(A >= 13) {
		printf("%lld\n", B);
	}
	else if(A >= 6) {
		printf("%lld\n", B / 2);
	}
	else {
		printf("0\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

#define mp      make_pair

int par[101010];

int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }

int main() {
        int n;
        scanf("%d", &n);
        set<int> g[101010];
        queue<pair<int, int>> both;
        for (int i = 0; i < n; i ++) par[i] = i;
        for (int i = 0; i < 2 * n - 2; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                if (g[a].count(b)) { 
                        both.emplace(a, b);
                        //cout << "both.emplace(" << a << ", " << b << ")" << endl;
                } else { 
                        g[a].insert(b);
                        g[b].insert(a);
                }
        }
        int ans = 0;
        while (!both.empty()) {
                ans ++;
                int a, b;
                tie(a, b) = both.front();
                both.pop();
                a = find(a), b = find(b);
                if (g[a].size() < g[b].size()) swap(a, b);
                a = par[a], b = par[b];
                if (a == b) continue;
                par[b] = a;
                g[a].erase(b);
                g[b].erase(a);
                for (auto c : g[b]) {
                        g[c].erase(b);
                        if (g[a].count(c)) { 
                                both.emplace(a, c);
                        } else { 
                                g[a].insert(c);
                                g[c].insert(a);
                        }
                }
                g[b].clear();
        }
        puts(ans == n - 1 ? "YES" : "NO");
        return 0;
}



Measured memory_bytes: 24064
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll N;
    cin >> N;

    string s;
    cin >> s;

    ll ans = 0;

    ll lhs = 0, rhs = N - 1;

    while (true)
    {
        while (lhs < N  && s[lhs] == 'R') { ++lhs; }
        while (rhs >= 0 && s[rhs] == 'W') { --rhs; }

        if (rhs <= lhs) { break; }

        ++lhs;
        --rhs;

        ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3728
fun main(args: Array<String>) {
    a44(readLineList())
}

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

fun a44(args: Array<String>) {
    if (args.size != 4) {
        throw IllegalArgumentException()
    }
    val (n, k, x, y) = args.map { it.toInt() }
    print(when {
        n > k -> x * k + y * (n - k)
        else -> x * n
    })
}

Measured memory_bytes: 33720
#include<stdio.h>
int ta[10010],to[60010],nt[60010],id[10010],cmp[100010],r=0,f[10010]={0};
void sdfs(int e,int s,int k){
  int i;
  f[s]++;
  for(i=ta[s];i+1;i=nt[i]){
    if(i<e&&k<0&&f[to[i]]==0||i>=e&&k>=0&&f[to[i]]==1)sdfs(e,to[i],k);
  }
  k<0?(id[r++]=s):(cmp[s]=k);
}
void scc(int v,int e,int *a,int *b){
  int i,k;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<e;i++){
    nt[i  ]=ta[to[i+e]=a[i]];
    nt[i+e]=ta[to[i  ]=b[i]];
    ta[a[i]]=i;
    ta[b[i]]=i+e;
  }
  for(i=k=0;i<v;i++){
    if(f[i]==0)sdfs(e,i,-1);
  }
  for(i=r;i;i--){
    if(f[id[i-1]]==1)sdfs(e,id[i-1],id[i-1]);
  }
}
int main(){
  int v,e,a[100010],b[100010],s,t,i;
  scanf("%d %d",&v,&e);
  for(i=0;i<e;i++)scanf("%d %d",&a[i],&b[i]);
  scc(v,e,a,b);
  for(i=0;i<v;i++){
    if(i-cmp[i])break;
  }
  printf("%d\n",i-v?1:0);
  return 0;
}

Measured memory_bytes: 660
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int A, B, K;
	cin >> A >> B >> K;

	for (int i = A; i <= B; i++){
	    if(i<A+K)cout<<i<<endl;
	    else if(i>B-K)cout<<i<<endl;
	}
}


Measured memory_bytes: 256
def o(a):
    for i in range(len(a)):
        a[i]=[a[i],i+1]
    return a             

n = int(input())
a = list(map(int, input().split()))

a=o(a)

q=[0]*n

for i in range(len(a)):
    q[a[i][0]-1]=a[i][1]

for i in q:
    print(i," ",end='')

Measured memory_bytes: 21532
import numpy as np
import bisect
def main():
    n,X = map(int,input().split())
    x = [int(i) for i in input().split()]
    index = bisect.bisect_left(x,X)
    x.insert(index,X)
    diff = []
    for i in range(1,n+1):
        diff.append(x[i]-x[i-1])
    diff = np.array(diff)
    ans = np.gcd.reduce(diff)
    print(ans)
main()


Measured memory_bytes: 38060
#include <iostream>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;

  	if (A>=13) {
      cout << B << endl;
    } else if (A>=6) {
      cout << B/2 << endl;
    } else {
      cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[200010];
int B[200010];
bool flag = true;
ll ans = 0;

queue<int> mx;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N; i++){
        int l = (i - 1 + N) % N;
        int r = (i + 1) % N;
        if(B[i] >= B[l] + B[r]) mx.push(i);
    }
    while(!mx.empty()){
        int id = mx.front();
        mx.pop();
        int l = (id - 1 + N) % N;
        int r = (id + 1) % N;
        ans += B[id] / (B[l] + B[r]);
        B[id] %= B[l] + B[r];
        if(B[id] < A[id]){
            if((A[id] - B[id]) % (B[l] + B[r]) != 0){
                cout << -1 << endl;
                return 0;
            }
            ans -= (A[id] - B[id]) / (B[l] + B[r]);
            B[id] = A[id];
        }
        int r2 = (r + 1) % N;
        int l2 = (l - 1 + N) % N;
        if(B[r] > B[id] + B[r2] && B[r] != A[r]) mx.push(r);
        if(B[l] > B[id] + B[l2] && B[l] != A[l]) mx.push(l);
    }
    for(int i = 0; i < N; i++) if(A[i] != B[i]) flag = false;
    cout << (flag ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 2304
package main

import "fmt"

func main() {
	var l int
	var s string

	fmt.Scanln(&l)
	fmt.Scanln(&s)

	d := false
	if l == 0 || l%2 != 0 {
		d = false
	} else {
		if s[0:l/2] == s[(l/2):] {
			d = true
		}
	}
	if d == false {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
from bisect import bisect_left

n = int(readline())
A = list(map(int,readline().split()))
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = map(int, readline().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)
    
que = deque()
inf = 10**9+1
dp = [inf]*n
que.append((0,-1))
chk = [False]*n
chk[0] = True
cnt = 0
ans = [1]*n

while que:
  now,d = que.pop()
  if d != -1:
    dp[now] = d
  else:
    ind = bisect_left(dp,A[now])
    que.append((ind,dp[ind]))
    dp[ind] = A[now]
    ans[now] = bisect_left(dp,inf)
    cnt += 1
    for i in g[now]:
      if not chk[i]:
        chk[i] = True
        que.append((i,-1))
  if cnt == n:
    break
        
print(*ans,sep='\n')

Measured memory_bytes: 78172
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    while True:
        if a[i] % 2 == 1:
            break
        if a[i] % 2 == 0:
            a[i] = a[i] // 2
            count += 1
print(count)

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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }



int n, m;

int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    string str1, str2, str3;


    cin >> str1 >> str2 >> str3;

    if(str1.back() == str2.front() && str2.back() == str3.front()) {
        cout<< "YES" <<endl;
    } else {
        cout<< "NO" <<endl;
    }





    return 0;
}


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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int main()
{
	string s;
	getline(cin, s);
	char op = '0';
	int first = 0, second = 0;
	
	for(char c: s) {
		if(c == ' ') continue;
		
		if(c == '-' or c == '+') {
			op = c;
			continue;
		}
		
		if(op == '0') {
			first = first*10 + (c-'0');
		} else {
			second = second*10 + (c-'0');
		}
	}
	
	if(op == '+') cout << first + second;
	else cout << first - second;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(){
int a, b, c, d;

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




  if(a > b){
    d = a;
    a = b;
    b = d;
  }
   if(b > c){
    d = b;
    b = c;
    c = d;
  }
   if(a > b){
    d = a;
    a = b;
    b = d;
  }

  printf("%d %d %d\n", a,b,c);


  return 0;

}

Measured memory_bytes: 1776
s = list(input())

if s[0] == "k":
    li = []
    for i in range(6):
        li.append(s[len(s)-(6-i)])
    if "".join(li) == "eyence":
        print("YES")
        quit()

if s[0] + s[1] == "ke":
    li = []
    for i in range(5):
        li.append(s[len(s)-(5-i)])
    if "".join(li) == "yence":
        print("YES")
        quit()

if s[0] + s[1] + s[2] == "key":
    li = []
    for i in range(4):
        li.append(s[len(s)-(4-i)])
    if "".join(li) == "ence":
        print("YES")
        quit()

if s[0] + s[1] + s[2] + s[3] == "keye":
    li = []
    for i in range(3):
        li.append(s[len(s)-(3-i)])
    if "".join(li) == "nce":
        print("YES")
        quit()

if s[0] + s[1] + s[2] + s[3] + s[4] == "keyen":
    li = []
    for i in range(2):
        li.append(s[len(s)-(2-i)])
    if "".join(li) == "ce":
        print("YES")
        quit()

if s[0]  + s[1] + s[2] + s[3] + s[4] + s[5] == "keyenc":
    if s[len(s) - 1] == "e":
        print("YES")
        quit()

        
lis = []
for i in range(7):
    lis.append(s[len(s)-i-1])
if "".join(lis) == "keyence":
    print("YES")
    quit()

print("NO")

Measured memory_bytes: 3188
///HELLO THERE~!
///CREATED BY MD SADMAN MEHEDI SIVAN(IUT CSE-SWE^19)

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;

int main()
{
    fastio;

    int X;
    cin>>X;
    int h=X/500;
    int f=(X%500)/5;
    int r=h*1000+f*5;
    cout<<r;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, k; cin >> a >> b >> c >> k;
    if(k <= a) cout << k << endl;
    else if(k <= a + b) cout << a << endl;
    else cout << a - (k - a - b) << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}
template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    int n, m;
    read(n, m);
    vector<pair<ll,ll>> s;
    REP(i,n){
        ll a, b;
        read(a, b);
        s.push_back(make_pair(a,b));
    }
    sort(s.begin(), s.end());
    ll paid = 0;
    ll got = 0;
    for(int i = 0 ; i < n ; i++){
        if( got + s[i].second < m){
            got += s[i].second;
            paid += s[i].first * s[i].second ;
        }else{
            int remain = m - got;
            paid += s[i].first * remain;
            break;
        }
    }
    cout << paid << endl;
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 5328
#include<iostream>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  priority_queue<unsigned long long, vector<unsigned long long>, less<unsigned long long> > A;
  for(int i = 0; i < N; i++){
    unsigned long long tmp;
    cin >> tmp;
    A.push(tmp);
  }

  for(int i = 0; i < M; i++){
    unsigned long long x = A.top();
    A.pop();
    x /= 2;
    A.push(x);
  }
  
  unsigned long long ans = 0;
  for(int i = 0; i < N; i++){
    ans += A.top();
    A.pop();
  }

  printf("%llu\n", ans);
  
  
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    int x;
    rep(i,5) {
        cin>>x;
        if(x==0){
            cout<<i+1<<endl;
        }
    }
    return 0;
}

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


int main(void) {
    using namespace std;

    long n;
    cin >> n;
    vector<pair<long,long>> ba(n);
    for(auto &x: ba)
        cin >> x.second >> x.first;
    sort(ba.begin(), ba.end());

    long r = 0;
    for(auto &x: ba) {
        r += x.second;
        if(r > x.first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
    double a, l, x, d1, d2, lx;
    while(cin >> a >> l >> x)
    {
        lx = l + x;
        d1 = a * sqrt(l * l - a * a /4) /2;
        d2 = l * sqrt(lx * lx - l * l) / 2;
        printf("%.6f\n", d1 + d2) ;
    }
    return 0;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n;
    cin>>n;
    int w[n];
    int gokei = 0;
    REP(i, n){
        cin>>w[i];
        gokei += w[i];
    }
    int gokei2 = 0;
    int sa1, sa2;
    int sa3, sa4;
    REP(i, n){
        gokei2 += w[i];
        if(gokei2>gokei/2){
            sa1 = gokei2;
            sa2 = gokei-sa1;
            sa3 = gokei2-w[i];
            sa4 = gokei - sa3;
            break;
        }

    }

    int ans1 = abs(sa1-sa2);
    int ans2 = abs(sa3-sa4);

    cout<<min(ans1, ans2)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e10;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = INF;
    rep(i,1,sqrt(n)+1){
        if (n%i == 0){
            ll k1 = (to_string(n/i)).length();
            ll k2 = (to_string(i)).length();
            chmin(ans,max(k1,k2));
        }
    }
    PRINT(ans);
}



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

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0.0;
    for (int i = 1; i <= n; i++) {
        int tmp = i;
        double sum = 1.0;
        while (tmp < k) {
            tmp *= 2;
            sum *= 0.5;
        }
        ans += sum;
    }
    cout << fixed << setprecision(10);
    cout << ans * (1.0 / n) << 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++)
using p = pair<int,int>;
int main(){
    int h,w;
    long long m;
    cin >> h >> w >> m;
    vector <int> xx(h);
    vector <int> yy(w);
    set <p> s;
    rep(i,m){
        int x,y;
        cin >> x >> y;
        --x; --y;
        xx[x] += 1;
        yy[y] += 1;
        s.emplace (x,y);
    }
    int mx = 0;
    int my = 0;
    rep(i,h) mx = max(mx,xx[i]);
    rep(i,w) my = max(my, yy[i]);
    int ans = mx + my;
    vector<int> xm,ym;
    rep(i,h){
        if (xx[i] == mx) xm.push_back(i);
    }
    rep(i,w){
        if (yy[i] == my) ym.push_back(i);
    }
    for (int j : xm) for (int k : ym){
        if (s.find({j,k}) == s.end()){
            cout << ans << endl;
            return 0;
        }
    }
    ans -= 1;
    cout << ans << endl;
}

Measured memory_bytes: 23688
N = int(input())
A = [int(x) for x in input().split()] 
S1, S2 = 0, sum(A)
L = []
for i in range(N):
  L.append(abs(S1 - S2))
  S1, S2 = S1 + A[i], S2 - A[i]
print(min(L))

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

int calc(int a, int b, int c, int d){
  int e = min(a,c);
  a -= e;
  c -= e;
  b *= 2;
  d *= 2;
  if(a != 0){
    int x = min(a,d);
    e += x;
    a -= x;
    d -= x;
  }
  else if(c != 0){
    int x = min(c,b);
    e += x;
    c -= x;
    b -= x;
  }
  e += b/2;
  e += d/2;
  return e;
}
    

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<map<int,int>> P(M);
  vector<int> ones(M);
  vector<int> pairs(M);
  for(int i=0; i<N; i++){
    int x = vec.at(i) %M;
    if(P.at(x).count(vec.at(i))){
      P.at(x)[vec.at(i)]++;
    }
    else{
      P.at(x)[vec.at(i)] = 1;
    }
    if(P.at(x)[vec.at(i)] %2 == 0){
      pairs.at(x)++;
      ones.at(x)--;
    }
    else{
      ones.at(x)++;
    }
  }
  
  int ans = 0;
  
  for(int i=0; i<M; i++){
    int a = i;
    int b = (M - i)%M;
    if(a == b){
      ans += (ones.at(a) + pairs.at(a)*2)/2;
    }
    else if(a < b){
      ans += calc(ones.at(a), pairs.at(a), ones.at(b), pairs.at(b));
    }
  }
  cout << ans << endl;
}  

Measured memory_bytes: 10752
n = gets.to_i

sum = 0
first = n
d = 1

until first < 10
  sum += first % 10
  first /= 10
  d += 1
end
sum += first

max = [first.to_s, "9" * (d - 1)].join.to_i
puts n < max ? 9 * (d - 1) + (first - 1) : sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

#define MOD 998244353
#define FACT_MAX 1000000

long long fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0LL;
    if(k==n || k==0) return 1LL;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

using mint = atcoder::modint998244353;

int n;
int cnt[100001];

int main() {
    Combinatrics comb;
    deque<vector<mint>> deq;
    cin>>n;
    REP(i,100001)cnt[i]=0;
    REP(i,2*n){
        int h;
        cin>>h;
        cnt[h]++;
    }
    REP(i,100001){
        if(cnt[i]){
          auto c = cnt[i];
          vector<mint> m;
          REP(j,c/2+1){
            mint a = comb.nck(c,2*j);
            a *= fact[2*j];
            a /= fact[j];
            a /= comb.power(2,j);
            m.push_back(a);
          }
          deq.push_back(m);
        }
    }
    
    while(deq.size() > 1){
      auto conv = atcoder::convolution(deq[0],deq[1]);
      deq.pop_front();
      deq.pop_front();
      deq.push_back(conv);
    }

    mint ret = 0;
    REP(i,deq[0].size()){
      //cerr<<i<<" "<<(((fact[2*n-2*i])%MOD)*comb.inv(fact[n-i])%MOD)*comb.inv(comb.power(2,n-i))%MOD<<endl;
      mint m = fact[2*n-2*i];
      m /= fact[n-i];
      m /= comb.power(2,n-i);
      m *= deq[0][i];
      ret += (i%2) ? -m:m;
    }
    cout<<ret.val()<<endl;
}

Measured memory_bytes: 17376
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val x, y = sc.nextLong
    println(if (x % y == 0) (-1) else {
      var i = 1
      while (i * x % y == 0) (i += 1)
      i * x
    })
  }

  def gcd(i: Int, j: Int): Int = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}



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

int main() {
  int A, B, count = 0;
  cin >> A >> B;
  while(A<=B){
    int a,b,c,d;
    a = A % 10;
    b = (A / 10) % 10;
    c = (A / 1000) % 10;
    d = A / 10000;
    if(a == d && b == c)
      count++;
    A++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256