akhauriyash/Code-Regression huggingface dataset:
searching_word = input()
sentence = []
counter = 0
try:
  while True:
    words = input().lower().split()
    if words == 'end_of_text':
      break
    for i in range(len(words)):
      sentence.append(words[i])
except EOFError:
  pass

for i in range(len(sentence)):
  if sentence[i] == searching_word:
    counter += 1
print(counter)


Measured memory_bytes: 5560
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define init(a) memset((a),0,sizeof(a))
using namespace std;
typedef long double D;
typedef vector<D> P;
const D EPS = 1e-8;

int N,Q;
P objp[55];
D objr[55];
long long objl[55];

inline P mul(P p, D d){
  rep(i,p.size())p[i] *= d;
  return p;
}

inline P add(P a, P b){
  rep(i,a.size())a[i] += b[i];
  return a;
}

inline D dis2(const P &a, const P &b){
  D x = a[0]-b[0], y = a[1]-b[1], z = a[2]-b[2];
  return x*x+y*y+z*z;
}

inline int intersect(int c, P l, P r){
  D r2 = objr[c]*objr[c];
  bool f1 = (dis2(objp[c],l)<r2+EPS), f2 = (dis2(objp[c],r)<r2+EPS);
  if(f1&&f2)return 0;
  if(f1||f2)return 1;

  rep(azu,50){
    P m1 = mul(add(mul(l,2),r),1.0/3), m2 = mul(add(l,mul(r,2)),1.0/3);
    D d1 = dis2(objp[c],m1), d2 = dis2(objp[c],m2);
    if(d1<d2)r = m2;
    else l = m1;
  }
  if(dis2(objp[c],l)<r2+EPS)return 1;
  return 0;
}

int main(){
  scanf("%d%d",&N,&Q);

  rep(i,N){
    objp[i].resize(3);
    rep(j,3)scanf("%Lf",&objp[i][j]);
    scanf("%Lf%lld",&objr[i],&objl[i]);
  }

  rep(i,Q){
    P a(3), b(3);
    rep(i,3)scanf("%Lf",&a[i]);
    rep(i,3)scanf("%Lf",&b[i]);
    long long ans = 0;
    rep(j,N){
      if(intersect(j,a,b))ans += objl[j];
    }
    printf("%lld\n",ans);
  }
}

Measured memory_bytes: 1220
import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        X, K, D = map(int, self.input_data().split())
        if abs(X) > K * D:
            result = abs(X) - K * D
        else:
            if int(abs(X) / D) % 2 == K % 2:
                result = abs(X) - int(abs(X) / D) * D
            else:
                result = (int(abs(X) / D) + 1) * D - abs(X)

        print(str(result))


solver = Solver(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 9976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, x;
  cin >> N;
  x = 0;
  vector<string> blue(N);
  vector<int> b(N);
  vector<string> red(M);
  for(int i = 0; i < N; i++){
    cin >> blue.at(i);
  }
  cin >> M;
  for(int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(blue.at(i) == blue.at(j)){
        b.at(i)++;
      }
    }
    for(int j = 0; j < M; j++){
      if(blue.at(i) == red.at(j)){
        b.at(i)--;
      }
    }
    if(x < b.at(i))x = b.at(i);
  }
  cout << x << endl;
}
    
    
         
      
      
  
  
  
 

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





int main(){
	int N,x;
	cin>>N>>x;
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	
	int ans = 0;
	for(int i=0;i<N;i++){
		if(x>=a[i]){
			x-=a[i];
			ans++;
		}
		else{
			break;
		}
	}
	
	if(ans==N&&x!=0)ans--;
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll c[200010],dp[200010],ch[200010];
int main() {
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>c[i];
	}
	dp[0]=1;
	for(ll i=1;i<=n;i++){
		if(c[i-1]!=c[i]){
			ch[c[i-1]]=i-1;
			if(ch[c[i]]!=0){
				dp[i]+=dp[ch[c[i]]];
			}
		}
		dp[i]+=dp[i-1];
		dp[i]%=inf;
	}
	cout << dp[n];
	// your code goes here
	return 0;
}

Measured memory_bytes: 4992
while True:
    n, q = map(int, input().split())
    if n == 0: break
    ls = []
    for i in range(n):
        ls.append(list(map(int, input().split())))

    max_q = 0
    date = 0
    for i in range(1, 101):
        count = 0
        for j in range(len(ls)):
            if i in ls[j][1:]:
                count += 1
                if count > max_q:
                    max_q = count
                    date = i
    if max_q < q:
        print(0)
    else:
        print(date)

Measured memory_bytes: 7604
import fractions

def prime_divs(n):
    divs = {}
    for i in range(2, int(n**.5)+1):
        while n % i == 0:
            if i not in divs:
                divs[i] = 0
            divs[i] += 1
            n //= i
    if n != 1:
      if n not in divs:
      	divs[n] = 0
      divs[n] += 1
    return divs

  
A, B = map(int, input().split())
print(len(prime_divs(fractions.gcd(A, B))) + 1)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  int sum=1;
  vi A(N);
  rep(i,0,N){
    cin>>A[i];
    sum=sum*A[i]/__gcd(sum,A[i]);
  }
  int ans=M/(sum/2)-M/sum;
  int memo=0;
  while(A[0]%2==0){
    memo++;
    A[0]/=2;
  }
  rep(i,1,N){
    int cnt=0;
    while(A[i]%2==0){
      cnt++;
      A[i]/=2;
    }
    if(cnt!=memo) ans=0;
  }
  cout<<ans<<endl;
  }


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

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

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        k: i64, x: i64,
    }
    puts!("{}\n", if x <= 500 * k { "Yes" } else { "No" });
}

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


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,T;
  int c,t;
  int minsum = 1000000001;
  cin >> N >> T;
  for(int i=0; i<N; i++){
    cin >> c >> t;
    if(t <= T){
      minsum = min(minsum,c);
    }
  }
  if(minsum == 1000000001){
    cout << "TLE" << endl;
  } else {
    cout << minsum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// Problem : B - Unhappy Hacking (ABC Edit)
// Contest : AtCoder - AtCoder Beginner Contest 043
// URL : https://atcoder.jp/contests/abc043/tasks/abc043_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	stack<char> st;
	string s, ans = "";
	cin >> s;
	for(char c:s){
	    if(c=='B'){
	        if(!st.empty())
	            st.pop();
	    }
	    else{
	        st.push(c);
	    }
	}
	while(!st.empty()){
	    ans+=st.top();
	    st.pop();
	}
	for(int i = ans.size()-1; i>=0; i--){
	    cout << ans[i];
	}
	return 0;
}

Measured memory_bytes: 256
import sys

lines = []
for line in sys.stdin:
    lines.append(line.strip().split(','))

field = [[0 for i in range(10)] for j in range(10)]

def drop(x, y, z):
    if z==1:
        for i in range(-1,2):
            for j in range(-1,2):
                if abs(i)+abs(j)<2 and 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1
    elif z==2:
        for i in range(-1,2):
            for j in range(-1,2):
                if 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1
    else:
        for i in range(-2,3):
            for j in range(-2,3):
                if abs(i)+abs(j)<3 and 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1



for line in lines:
    x,y,z = map(int, line)
    drop(x,y,z)

n = 0
m = 0
for f in field:
    for e in f:
        if e > m:
            m = e
        if e==0:
            n+=1

print(n)
print(m)



Measured memory_bytes: 5608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

ll count_sort(int s, int e, vl &S, vl &temp) {
	if (e - s <= 1) {
		return 0;
	}
	int mean = (e + s) / 2;
	ll ans = 0;
	ans += count_sort(s, mean, S, temp);
	ans += count_sort(mean, e, S, temp);
	for (int i = s; i < e; i++) {
		temp[i] = S[i];
	}
	int i1 = s;
	int i2 = mean;
	int is = s;
	while (is<e) {
		if (i1 != mean && (i2 == e || temp[i1] <= temp[i2])) {
			S[is] = temp[i1];
			is++;
			i1++;
		}
		else {
			S[is] = temp[i2];
			ans += mean - i1;
			is++;
			i2++;
		}
	}
	return ans;
}


int main() {
	ll n;
	ll k;
	cin >> n >> k;
	vl S(n+1);
	S[0] = 0;
	int a;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		S[i] = S[i - 1] +a-k;
	}
	vl temp(n + 1);
	cout << (n + 1)*n / 2 - count_sort(0, n + 1, S, temp) << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[100010],finv[100010],inv[100010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,100010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll n;cin>>n;
    combinit();
    vector<ll>x(n);
    rep(i,n)cin>>x[i];
    ll k=1;
    REP(i,1,n){
        k*=i;
        k%=inf;
    }
    vector<ll>a(n-1);
    a[0]=k;
    REP(i,1,n-1){
        k*=i%inf;
        k%=inf;
        k*=inv[i+1]%inf;
        k%=inf;
        a[i]=a[i-1]+k;
        a[i]%=inf;
    }
    vector<ll>b(n);
    rep(i,n-1){
        b[i]=x[i+1]-x[i];
    }
    ll ans=0;
    rep(i,n-1){
        ans+=(a[i]*b[i])%inf;
        ans%=inf;
    }
    if(ans<0)ans+=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
import heapq as HQ

class Heap:
  def __init__(self, data, reverse=False):
    self.reverse = -1 if reverse else 1
    self.data = [self.reverse * d for d in data]
    HQ.heapify(self.data)
  def push(self, x): return HQ.heappush(self.data, self.reverse * x)
  def pop(self): return self.reverse * HQ.heappop(self.data)

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()

def fizzbuzz(i):
    return i % 3 == 0 or i % 5 == 0

print(np.sum([i for i in range(n+1) if not fizzbuzz(i)]))

Measured memory_bytes: 52096
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()

	s := []byte(readString())
	te := []byte{'g', 'p'}
	j := 0
	ans := 0
	for i := 0; i < len(s); i++ {
		if s[i] == 'g' {
			if te[j] == 'p' {
				ans++
			}
		} else {
			if te[j] == 'g' {
				ans--
			}
		}
		j = 1 - j
	}
	println(ans)
}

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


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int N[30], n, w, copy;
	int a, b, i;
	
	scanf("%d", &w);
	for( i = 0; i < w; i++){
		N[i] = i+1;
	}
	scanf("%d", &n);
	for( i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);
		copy = N[a-1];
		N[a-1] = N[b-1];
		N[b-1] = copy;
	}
	for( i = 0; i < w; i++){
		printf("%d\n", N[i]);
	}
	return 0;
}

Measured memory_bytes: 596
n,m,k=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)
B=gets.split.map(&:to_i)
a,b,ans,j=[0],[0],0,m
(0...n).each{|i|a<<(a[i]+A[i])}
(0...m).each{|i|b<<(b[i]+B[i])}
(0..n).each do |i|
  break if a[i]>k
  j-=1 while b[j]>k-a[i]
  ans=[ans,i+j].max
end
puts ans

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

int main(){
  ll n,q;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  cin>>q;
  ll s[q+1];
  vector<ll> nm(100001,0);
  s[0]=0;
  ll b,c;
  for(int i=0;i<n;i++){s[0]+=a[i];nm[a[i]]++;}
  for(int i=1;i<=q;i++){
    cin>>b>>c;
    nm[c]+=nm[b];
    s[i]=s[i-1]+nm[b]*(c-b);
    nm[b]=0;
    cout<<s[i]<<endl;
  }
}


Measured memory_bytes: 5572
N = int(input())
X = []
for i in range(N):
  x = input().split(" ")
  X.append([float(x[0]), x[1]])

total = 0  
for x in X:
  if x[1] == "JPY":
    total += x[0]
  else:
    total += x[0] * 380000.0
print(total)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

int dp[31][1<<16];

int main(){
  int total_light_patterns;
  int total_techniques;
  while(~scanf("%d %d",&total_light_patterns,&total_techniques)){
    if(total_light_patterns == 0
       && total_techniques == 0) break;

    vector<int> light_patterns;
    for(int light_idx=0;light_idx<total_light_patterns;light_idx++){
      int bits = 0;
      for(int j=0;j<16;j++){
	int is_light;
	scanf("%d",&is_light);
	if(is_light > 0) bits |= (1<<j);
      }
      light_patterns.push_back(bits);
    }
    vector<int> techniques;
    for(int tech_idx=0;tech_idx<total_techniques;tech_idx++){
      int bits = 0;
      for(int j=0;j<16;j++){
	int is_light;
	scanf("%d",&is_light);
	if(is_light > 0) bits |= (1<<j);
      }
      techniques.push_back(bits);
    }

    memset(dp,-1,sizeof(dp));
    dp[0][0] = 0;
    for(int light_idx=0;light_idx<total_light_patterns;light_idx++){
      for(int prev=0;prev<=(1<<16)-1;prev++){
	if(dp[light_idx][prev] == -1) continue;
	int next = (prev | light_patterns[light_idx]);
	for(int tech_idx=0;tech_idx<total_techniques;tech_idx++){
	  dp[light_idx+1][next ^ (next & techniques[tech_idx])]
	    = max(dp[light_idx][prev] + __builtin_popcount(next & techniques[tech_idx]),
		  dp[light_idx + 1][next ^ (next & techniques[tech_idx])]);
	}
      }
    }

    int res = 0;
    for(int S=0;S<=(1<<16)-1;S++){
      res = max(res,dp[total_light_patterns][S]);
    }
    printf("%d\n",res);
  }
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b,c; cin >> a >> b >> c;
  int M = max(max(a,b),c);
  int S = a+b+c;
    
  int x = S%2==3*M%2 ? M:M+1;
  int ans = 3*x-S;
  ans /= 2;

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


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

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

const int maxn = 110,maxm = 5500;
#define inf 10000

int cost[maxn][maxn]={};
int mincost[maxn] = {};
bool used[maxn] = {};
int n,m,a,b,temp;
char t;

int main()
{
	while(cin >> n && n)
	{
		cin >> m;
		memset(cost, inf, sizeof(cost));
		memset(mincost, inf, sizeof(mincost));
		memset(used, false, sizeof(used));
		mincost[0] = 0;
		
		int ans = 0;
		REP(m)
		{
			cin >> a >> t >> b >> t >> temp;
			cost[a][b] = (temp/100)-1;
			cost[b][a] = cost[a][b];
		}
		
		while(1)
		{
			int minv = n;
			rep(i,n)if(!used[i] &&(minv == n ||mincost[i] < mincost[minv])) minv = i;
			if(minv == n) break;

			used[minv] = true;
			ans += mincost[minv];

			REP(n) mincost[i] = min(mincost[i], cost[minv][i]);
		}
		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

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

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

const ll MAX_N = 100000 * 2;

// Union-Find
ll par[MAX_N];
ll u_rank[MAX_N];

void init(ll n){
	for (ll i = 0; i < n; i++){
		par[i] = i;
		u_rank[i] = 0;
	}
}

ll find(ll x){
	if (par[x] == x){
		return x;
	}
	else{
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y){
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (u_rank[x] < u_rank[y]){
		par[x] = y;
	}
	else{
		par[y] = x;
		if (u_rank[x] == u_rank[y]) u_rank[x]++;
	}
}

bool same(ll x, ll y){
	return find(x) == find(y);
}

struct edge{ ll u, v, cost; };

bool comp_p(const pll& l, const pll& r){
	return l.second < r.second;
}

bool comp_e(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

int main(){
	ll N;
	cin >> N;
	vector<pll> P;
	vector<pll> X, Y;
	ll i, j, k;
	for (i = 0; i < N; i++){
		ll x, y;
		cin >> x >> y;
		X.push_back(pll(i, x));
		Y.push_back(pll(i, y));
	}
	sort(X.begin(), X.end(), comp_p);
	sort(Y.begin(), Y.end(), comp_p);
	vector<edge> E;
	for (i = 0; i < N - 1; i++){
		ll u = X[i].first;
		ll v = X[i + 1].first;
		edge e;
		e.u = u;
		e.v = v;
		e.cost = X[i + 1].second - X[i].second;
		E.push_back(e);
		u = Y[i].first;
		v = Y[i + 1].first;
		edge f;
		f.u = u;
		f.v = v;
		f.cost = Y[i + 1].second - Y[i].second;
		E.push_back(f);
	}
	sort(E.begin(), E.end(), comp_e);
	ll M = E.size();
	init(M);
	ll ans = 0;
	for (i = 0; i < M; i++){
		edge e = E[i];
		if (!same(e.u, e.v)){
			unite(e.u, e.v);
			ans += e.cost;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 14044
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    var a: Array<Long> = Array(n, {i -> cin.nextLong()})

    val a_sorted = a.sorted()

    var sum: Long = 0
    var too_big = 0
    for (i in 0..n-1) {
        if (a_sorted[i] > sum*2) {
            too_big = i
        }
        sum += a_sorted[i]
    }

    println(n-too_big)
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 2E5 + 10;

int a[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		scanf("%d", a + i);
		a[i] -= i;
	}
	nth_element(a, a + n / 2, a + n);
	ll ans = 0;
	for (int i = 0; i < n; ++i)
		ans += abs(a[i] - a[n / 2]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int x,i,n;
    scanf(" %d",&n);
    for(i=1; i<=n; i++){
        x = i;
        if(x%3==0){
            printf(" %d",i);
        }else if(x%10==3){
            printf(" %d",i);
        }else{
            while(x!=0){
                x=x/=10;
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2088
#define task "A"
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define int long long
#define pii pair<int,int>
#define piii pair<pii,pii>
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(),a.end()
#define bug(x) cout << x << ' '
#define split cout << "\n============\n"
using namespace std;
const int N = 105;
int n,m,a[N][N];
int d[N][N][2];
int dx[2]={0,1};
int dy[2]={1,0};
bool ok(int x,int y) {return x<=n&&y<=m;}
signed main()
{
    //freopen(task".inp","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    forinc(i,1,n)
    forinc(j,1,m)
    {
        char c;
        cin >> c;
        if(c=='#') a[i][j]=1;
        d[i][j][0]=d[i][j][1]=1000000000;
    }
    priority_queue<piii,vector<piii>,greater<piii> > q;
    if(a[1][1])
    {
        d[1][1][1]=1;
        q.push({{1,1},{1,1}});
    }
    else
    {
        d[1][1][0]=0;
        q.push({{0,0},{1,1}});
    }
    while(!q.empty())
    {
        int D=q.top().st.st;
        int cm=q.top().st.nd;
        int x =q.top().nd.st;
        int y =q.top().nd.nd;
        q.pop();
        forinc(t,0,1)
        {
            int x1 = x+dx[t];
            int y1 = y+dy[t];
            if(!ok(x1,y1)) continue;
            int cl = cm?1-a[x1][y1]:a[x1][y1];
            if(!cl)
            {
                if(d[x1][y1][cm]>D)
                    q.push({{d[x1][y1][cm]=D,cm},{x1,y1}});
            }
            else
            {
                if(cm)
                {
                    if(d[x1][y1][0]>D)
                    q.push({{d[x1][y1][0]=D,0},{x1,y1}});
                }
                else
                {
                    int c = 1;
                    if(d[x1][y1][c]>D+1)
                    q.push({{d[x1][y1][c]=D+1,c},{x1,y1}});
                }
            }
        }
    }
    cout << min(d[n][m][0],d[n][m][1]);
}





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

int main() {
  int n;cin>>n;
  vector<int>v(n);
  rep(i,n)cin>>v[i];
  sort(all(v));
  double ans=v[0];
  for(int i=1;i<n;i++){
    ans=(ans+v[i])/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////


int main(){
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ll ans=inf;
    for(int i=0;i+k-1<=n-1;i++){
        ans=min(ans,a[i+k-1]-a[i]);
    }
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<long long int> v;
	long long int s = 0;
	
	for (int i = 0; i < n; i++) {
		long long int t;
		cin >> t;
		if (i % 2 == 0)
			s += t;
		else
			s -= t;
		v.push_back(t);
	}
	cout << s << " ";
	for (int i = 0; i < n - 1; i++) {
		s = (v[i] - s / 2) * 2;
		cout << s << " ";
	}
}














Measured memory_bytes: 2164
#include<stdio.h>
int main(){
	int a[4][14],n,i,j;
	scanf("%d",&n);
	
	for(i=0;i<4;i++){
		for(j=0;j<14;j++){
			a[i][j]=0;
		}
	}
	
	scanf("%*c");
	for(i=0;i<n;i++){
		char b;
		int c;
		scanf("%c %d\n",&b,&c);
		if(b=='S'){
			a[0][c]=1;
		}else if(b=='H'){
			a[1][c]=1;
		}else if(b=='C'){
			a[2][c]=1;
		}else if(b=='D'){
			a[3][c]=1;
		}
	}
	
	char pattern[] = {'S','H','C','D'};
	for(i=0;i<4;i++){
		for(j=1;j<14;j++){
			if(a[i][j]==0){
				printf("%c %d\n",pattern[i],j);
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#define N 1000000
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
	return x * f;
}
int k,x;
int main()
{
	k = read() ,x = read();
	int l = max(-N , x-k+1);
	int r = min(N , x+k-1);
	for(int i=l;i<=r;++i)
		printf("%d ",i);
	return 0;
}

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

int main()
{
	char s[3][128];
	int n;
	scanf("%d", &n);
	for (int i{}; i < 3; i++)
		scanf("%s", s[i]);
	
	int count{};
	for (int i{}; i < n; i++)
	{
		char tmp[3];
		for (int j{}; j < 3; j++)
			tmp[j] = s[j][i];
		std::sort(tmp, tmp + 3);
		if (tmp[0] == tmp[2]) continue;
		if (tmp[0] == tmp[1] || tmp[1] == tmp[2])
			count++;
		else
			count += 2;
	}
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,a[200010]={},opppa,cnt=0;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> opppa;
    if(a[opppa]==0){
      cnt++;
    }
    a[opppa]++;
  }
  sort(a,a+200010);
  if(cnt<=k){
    cout << 0 << endl;
    return 0;
  }
  int tanni=0;
  int i=0;
  while(cnt>k){
    if(a[i]!=0){
      tanni+=a[i];
      cnt--;
    }
    i++;
  }
  cout << tanni << endl;
  return 0;
}	


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

void ans(bool flag){
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << 'A' << b[0] << 'C' << endl;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

ll N;

int main(void) {
    cin >> N;

    map<map<char, int>, ll> m;

    rep(i, N) {
        string str;
        cin >> str;
        map<char, int> chars;
        rep(k, 10) {
            chars[str[k]] += 1;
        }

        m[chars] += 1;
    }

    ll ans = 0;
    for (auto t : m) {
        auto val = t.second;
        ans += val * max(1LL, val - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 49152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 try{
			 int W,H,x,y,r;
			 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			 String str = br.readLine();
			 String[] strAry = str.split(" ");
			 
			 W = Integer.parseInt(strAry[0]);
			 H = Integer.parseInt(strAry[1]);
			 x = Integer.parseInt(strAry[2]);
			 y = Integer.parseInt(strAry[3]);
			 r = Integer.parseInt(strAry[4]);
			 
			 if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
				 System.out.println("Yes");
			 }else{
				 System.out.println("No");
			 }
		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}

}

Measured memory_bytes: 26212
import fractions
n=int(input())
t=[int(input()) for _ in range(n)]
t=sorted(t)[::-1]
x=t.pop()
while(t):
     y=t.pop()
     x=x*y//fractions.gcd(x,y)
     if x>5*10**17:
          break
print(x)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
	vector<int> vs(5);
	rep(i, 5) {
		cin >> vs[i];
	}
	rep(i, 5) {
		if (vs[i] != i + 1) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	return 0;
}
	

Measured memory_bytes: 3592
use std::io;
use std::cmp;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    let b = read_line().chars().nth(0);
    if b == Some('A') {
        println!("T");
    }
    if b == Some('T') {
        println!("A");
    }
    if b == Some('G') {
        println!("C");
    }
    if b == Some('C') {
        println!("G");
    }
    
}



Measured memory_bytes: 4352
#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 << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 3608
N = int(input())
S = input()

stk = []
for s in S:
    if len(stk) == 0 or stk[-1] == ')' or s == '(':
        stk.append(s)
    else:
        stk.pop()

print('(' * stk.count(')') + S + ')' * stk.count('('))


Measured memory_bytes: 3064
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    A, V = MI()
    B, W = MI()
    T = I()
    diff = abs(A - B)
    v = (V - W) * T

    # print('v', v)
    # print(diff - v)

    if diff - v > 0:
        print('NO')
    else:
        print('YES')




if __name__ == '__main__':
    main()


Measured memory_bytes: 10012
#include <iostream>
#include <cmath>
#include <vector>
#include <climits>
#include <cstdlib>
using namespace std;
int main()
{
    char input[8];
    vector<long> stack;
    while(cin >> input)
    {
        if(isdigit(*input))
        {
            long t = atol(input);
           stack.push_back(t);
        }
        else
        {
            long b = stack.back();
            stack.pop_back();
            long a = stack.back();
            stack.pop_back();
            switch(*input)
            {
            case '+':
                a += b;
                break;
            case '-':
                a -= b;
                break;
            case '*':
                a *= b;
                break;
            case '/':
                a /= b;
                break;
            default:
                break;
            }
            stack.push_back(a);
        }
    }
    cout << stack[0] << endl;
}

Measured memory_bytes: 1200
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int A, B;
    int c = 0;
    cin >> A >> B;
    for(int i = 0; i < 2; i++)
    {
        if(A > B)
        {
            c += A;
            A -= 1;
        }
        else
        {
            c += B;
            B -= 1;
        }
    }
    cout << c <<endl;
    return 0; 
}


Measured memory_bytes: 256
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<ll> V;


    
int main()
{
    ios;
    ld r;
    cin>>r;
    cout<<setprecision(10)<<(2*PI*r);
    return 0;
}


Measured memory_bytes: 3804
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

//s.find_by_order(index);
//s.order_of_key(value);
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

ll solve(){
    ll a,b,c,k; cin>>a>>b>>c>>k;
    ll ans = 0;
    ans+=min(k,a);
    k-=ans;
    ll count = min(k,b);
    k-=count;
    ans-=min(k,c);
    cout<<ans;
    return 0;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}  

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int
#define db long double
#define ull unsigned long long int
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
#define MAXN 1000005
 
using namespace std;

ll dp[405][405];
ll a[405];

ll recur(ll i,ll j)
{
	if(j<i) return 0;
	if(i==j) return 0;
	// if(j==i+1) return a[i]+a[j];
	if(dp[i][j]!=-1) return dp[i][j];

	ll res=5000000000000;
	ll sum=0;
	rep(k,i,j) sum+=a[k];
	for(ll k=i;k<j;k++)
	{
		res=min(res,recur(i,k)+recur(k+1,j)+sum);
	}
	return dp[i][j]=res;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tests=1;
    // cin>>tests;
    while(tests--)
    {
    	ll i,j,n;
    	cin>>n;
    	rep(i,1,n) cin>>a[i];
    	memset(dp,-1,sizeof(dp));

    	cout<<recur(1,n);

    }
    	return 0;
    
}

Measured memory_bytes: 4912
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        ans += tmp;
    }
    ans -= n;
    printf("%d\n", ans);
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string o, e;
    cin >> o;
    cin >> e;
    int i;
    for (i = 0; i < e.size(); ++i) {
        cout << o[i] << e[i];
    }
    if (o.size() > e.size()) cout << o[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>


using namespace std;
typedef long long ll;

int N, M, X, Y = 0;

int main(){

    cin >> N >> M >> X >> Y;

    vector<int > x;
    vector<int > y;

    for(int i = 0; i < N; i++){
        int t = 0;
        cin >> t;
        x.push_back(t);
    }

    for(int i = 0; i < M; i++){
        int t = 0;
        cin >> t;
        y.push_back(t);
    }

    //判定
    int flag = 0;
    int ans = 114514;
    for(int i = X + 1; i <= Y; i++){
        for(int j = 0; j < x.size(); j++){
            if(i <= x[j]){
                    //cout << "war" << endl;
                    flag = 1;
                    break;
            }
        }

        for(int j = 0; j < y.size(); j++){
            if(i > y[j]){
                //cout << "war" << endl;
                flag = 1;
                break;
            }
        }

        if(flag == 1){
            flag = 0;
            continue;
        }

        ans = i;
    }
    
    if(ans == 114514){
        cout << "War" << endl;    
    }else{
        cout << "No War" << endl;    
    }
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(K, A, B));
    }

    public static long solve(int K, int A, int B){
        long count = 0;

        if (A >= B-2)   return K+1;
        if (A-1 > K-2) return K+1;

        count = B;
        K = K-(A-1)-2;

        count += (int)K/2 * (long)(B-A) + K%2;

        return count;
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<cmath>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define show(x) cout<< #x << " = " << (x) << endl
#define show_array(arr) REP(i,int((arr).size()))cout<< #arr << "["<<i<<"]"<<"="<<arr[i]<<endl


int main(){
	
	ios::sync_with_stdio(false);
	ll N;
	cin>>N;
	vector<ll> arr(N);
	REP(i,N)cin>>arr[i];
	ll sell_count = 0;	
	sell_count = arr[0] - 1;
	ll P = 2;	
	for(ll i = 1; i < N; i++ ){
		
		if(arr[i] == P){
			P++;
			continue;
		}
	
		ll s_c = (arr[i]-1) / P ;
		sell_count += s_c;
	}

	cout<<sell_count<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
bool check(long long a){
	int z[6],f[6];
	for(int i=1;i<=5;i++){
		z[i]=a%10;
		f[6-i]=a%10;
		a=a/10;
	}
	for(int i=1;i<=5;i++){
		if(z[i]!=f[i]) return 0;
	}
	return 1;
}
int main(){
	long long a,b,ans=0;
	cin>>a>>b;
	while(a<=b){
		if(check(a)==1) ans++;
		a++;
	}
	cout<<ans;
	return 0;
}

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

typedef long long LL;
long long n,a,b,A,B;

int main(){
	cin>>n;
	cin>>A>>B;
//	cout<<A<<" "<<B<<endl;
	for(int i=2;i<=n;i++){
		cin>>a>>b;
		LL t=max((A+a-1)/a,(B+b-1)/b);
		A=t*a,B=t*b;
//		if(A<=B) A=A*a/__gcd(a,A),B=A*b/a;
//		else B=B*b/__gcd(b,B),A=B*a/b;
//		cout<<A<<" "<<B<<endl;
	}cout<<A+B<<endl;
	return 0;
}

Measured memory_bytes: 256
/*           pmaik
    ░▒▓█►─═ Maneesh ═─◄█▓▒░


          ( •̪●)
        ███████]▄▄▄▄▄▄▄▄▃  ▃  ▃ 
    ▂▄▅█████████▅▄▃▂
   [███████████████████]
  ...◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤......  */

#include<bits/stdc++.h>
using namespace std;
#define inf() ifstream cin("in00.txt")
#define onf() ofstream cout("out00.txt")
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<ll,ll>
#define fi first
#define se second
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

 
int main()
{
    fastio;
    ll n;
    cin>>n;
    string s;
    cin>>s;

    ll r=0,w=0,i,j;
    ll c=0,f=1;
    for(i=0; i<n; i++)
    {
        if(s[i]=='W')
            w++;
        else
            r++;
    }

    ll res=0;
    for(i=r; i<n; i++)
    {
        if(s[i]=='R')
            res++;
    }
    cout<<res<<endl;
    


    return 0;
}


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

#define FOR(i, l, r) for(size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
    int S, W;
    cin >> S >> W;
    if(W >= S) {
      cout << "unsafe" << endl;
    }
  	else {
    	cout << "safe" << endl;
  	}
    return 0;
}


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

int main(void) {
    int N, ans = 0;
    cin >> N;
    vector<int> V, value;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        V.push_back(tmp);
    }
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        value.push_back(V[i] - tmp);
    }

    for (int i = 0; i < N; i++) {
        ans += value[i] > 0 ? value[i] : 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256