akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

const int MAX_N = 3005;

typedef long double real;

int n;
real p[MAX_N],dp[MAX_N][MAX_N];

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%Lf",p+i);
	dp[0][0]=1;
	for (int i=1; i<=n; i++)
	{
		dp[i][0]=(1-p[i])*dp[i-1][0];
		for (int h=1; h<=i; h++)
			dp[i][h]=p[i]*dp[i-1][h-1]+(1-p[i])*dp[i-1][h];
	}
	real ans=0;
	for (int h=n; h>n-h; h--)
		ans+=dp[n][h];
	printf("%.10Lf\n",ans);
	return 0;
}


Measured memory_bytes: 139264
#include<stdio.h>

int main (){

  int a,b;
  int i;
  int c[3];
  int max;
  
  scanf("%d %d" ,&a, &b);
  
  c[0]=a+b;
  c[1]=a-b;
  c[2]=a*b;
  
  max=c[0];
  
  for(i=1;i<3;i++){
  	if(max<c[i]) max=c[i];
  }

  printf("%d" , max);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;
    cin>>s;
    int ans=0;
    int i=0;
    int j=(int)s.size()-1;
    while(i<j){
        if(s[i]!=s[j]) ans++;
        i++;
        j--;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let x: i64 = sc.cin();
    let mut u = 0;
    let mut ans = 1;
    for _ in 0..n {
        let ell: i64 = sc.cin();
        u += ell;
        if u <= x {
            ans += 1;
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define RevRange(container) container.rbegin(), container.rend()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

struct Bit{
    int n;
    vector<int> bit; // bit[0] は使われない
    Bit(int n){ this->n = n; bit = vector<int>(n+1); };
    
    void add(int a, int w){
        for(int x = a; x <= n; x += x & -x) bit[x] += w;
    }
    int sum(int a){
        int ret = 0;
        for(int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
};

bool f(int x, vector<int> &a, int n){
    vector<int> s(n+1);
    For(i, n) s[i+1] = s[i] + ((a[i] >= x) ? 1 : -1);
    For(i, n+1) s[i] += n+2;
    ll ans = 0;
    Bit bit(2*n+10);
    For(i, n+1){
        ans += bit.sum(s[i]);
        bit.add(s[i], 1);
    }
    ll m = (ll)n*(n+1)/2;
    return ans < (m+1)/2;
}

int main(){
    Cin(int, n);
    Cins(int, n, a);

    int lb = 0, ub = 1e9+1;
    while(ub - lb > 1){
        int m = (lb + ub) / 2;
        ((f(m, a, n)) ? ub : lb) = m;
    }
    sort(Range(a));
    Cout(lb);
}



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

int main(){
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  char i = S.at(K-1);
  if(i=='A'){
    S.at(K-1)='a';
  }else if(i=='B'){
    S.at(K-1)='b';
  }else{
    S.at(K-1)='c';
  }
  cout << S;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
#endif

    string s, t;
    cin >> s >> t;
    
    map<char, vi> m;
    rep(i, sz(s)) m[s[i]].pb(i);

    int runs = 0, i = -1;
    rep(j, sz(t)) {
        if (!m.count(t[j])) {
            cout << -1;
            return 0;
        }

        auto it = upper_bound(all(m[t[j]]), i);
        if (it == m[t[j]].end()) runs++, it = m[t[j]].begin();
        i = *it;
    }
    cout << (ll)runs * sz(s) + i + 1;

    return 0;
}


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

int main(){
	string S; cin >> S;
	
	int ans = 0;
	int count = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'A'|| S[i] == 'C'|| S[i] == 'G'|| S[i] == 'T'){
			count++;
			ans = max(ans, count);
		}
		else
		{
			count = 0;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
l = []
S = str(input())

for i in range(len(S)):
  l.append(S[i])

for i in range(len(l)):
  if ord(l[i]) + N > 90:
    l[i] = chr(ord(l[i]) + N - 26)
  else:
    l[i] = chr(ord(l[i]) + N)
ans = ''.join(l)
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
long long Q,H,S,D,N,ans,k,kk,kkk;
int main()
{
    cin>>Q>>H>>S>>D>>N;
    k=min(Q*4,min(H*2,S));//求Q,H,S 哪个便宜
    if(k*2<=D)//K便宜
    {
        cout<<k*N<<endl;
    }
    else//D便宜
    {
        cout<<((N%2)*k)+N/2*D<<endl;
    }
    return 0;
}

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

int main(){
	int n, sen, hyaku, juu, iti, count;
	cin >> n;
	sen = n / 1000;
	hyaku = (n - sen * 1000) / 100;
	juu = (n - sen * 1000 - hyaku * 100) / 10;
	iti = (n - sen * 1000 - hyaku * 100 - juu * 10) / 1;

	if (hyaku != juu)
		cout << "No" << endl;
	else if (hyaku == sen)
		cout << "Yes" << endl;
	else if (hyaku == iti)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a[x] ^= z;
    a[y] ^= z;
  }
  vector<int> cnt(16);
  for (int i = 0; i < n; i++) {
    ++cnt[a[i]];
  }
  int res = 0;
  int have = 0;
  for (int i = 1; i < 16; i++) {
    res += cnt[i] / 2;
    cnt[i] &= 1;
    have |= (cnt[i] << i);
  }
  vector<bool> ok(1 << 16);
  for (int mask = 0; mask < (1 << 16); mask++) {
    int here = 0;
    for (int i = 0; i < 16; i++) {
      if ((mask >> i) & 1) {
        here ^= i;
      }
    }
    ok[mask] = (here == 0);
  }
  vector<int> dp(1 << 16);
  for (int mask = 1; mask < (1 << 16); mask++) {
    if (mask & 1) continue;
    for (int smsk = mask; smsk > 0; smsk = (smsk - 1) & mask) {
      if (ok[smsk]) {
        dp[mask] = max(dp[mask], dp[mask ^ smsk] + 1);
      }
    }
  }
  cout << res + __builtin_popcount(have) - dp[have] << endl;
  return 0;
}


Measured memory_bytes: 3952
#include <iostream>
#include <vector>

using namespace std;

vector<int> abc(3);
vector<int> ab(2);

int main(){
    cin >> abc[0] >> abc[1] >> abc[2];

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

    int tmp1 = abc[2] - abc[0];
    int tmp2 = abc[2] - abc[1];
    
    ab[0] = tmp1;
    ab[1] = tmp2;

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

    int ans = 0;

    int tmp = ab[1] - ab[0];

    ans += ab[0];

    if(tmp%2 == 0){
        ans += tmp/2;
        cout << ans << endl;
        return 0;
    }
    else{
        tmp++;
        ans += tmp/2;
        ans++;
        cout << ans << endl;
        return 0;
    }
}



Measured memory_bytes: 256
"use strict"

function main(input) {

    let num = Number(input.split('\n')[0])
    let tmp = num
    let sum = 0
    for (let i = 1; i <= input.length; i++) {
        sum += tmp % 10 //一の位
        tmp = Math.floor(tmp / 10) //一桁削る
            // or 
            //tmp = (tmp-(tmp % 10) / 10
    }
    if (num % sum == 0) console.log('Yes')
    else console.log('No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author koneko096
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    DMegalomania solver = new DMegalomania();
    solver.solve(1, in, out);
    out.close();
  }

  static class DMegalomania {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();

      List<Pair<Integer, Integer>> lp = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        int a = in.nextInt(), b = in.nextInt();
        lp.add(new Pair<>(b, a));
      }

      Collections.sort(lp);

      long T = 0;
      for (Pair<Integer, Integer> p : lp) {
        T += p.getSc();
        if (p.getFs() < T) {
          out.println("No");
          return;
        }
      }
      out.println("Yes");
    }

  }


  static class Pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>>
      implements Comparable<Pair<T1, T2>> {
    T1 fs;
    T2 sc;

    public T1 getFs() {
      return fs;
    }

    public T2 getSc() {
      return sc;
    }

    public Pair(T1 fs, T2 sc) {
      this.fs = fs;
      this.sc = sc;
    }

    public int compareTo(Pair<T1, T2> o) {
      int fc = fs.compareTo(o.fs);
      if (fc != 0) {
        return fc;
      }
      return sc.compareTo(o.sc);
    }

    public String toString() {
      return "<" + "" + fs + ", " + sc + '>';
    }

  }


  static class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

  }
}



Measured memory_bytes: 62636
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
template <typename X, typename T> auto make_vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_vectors(X x, Y y, Z z, Zs... zs) { auto cont = make_vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <int32_t MOD>
struct mint {
    int32_t value;
    mint() : value() {}
    mint(int64_t value_) : value(value_ < 0 ? value_ % MOD + MOD : value_ >= MOD ? value_ % MOD : value_) {}
    inline mint<MOD> operator + (mint<MOD> other) const { int32_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> operator - (mint<MOD> other) const { int32_t c = this->value - other.value; return mint<MOD>(c <    0 ? c + MOD : c); }
    inline mint<MOD> operator * (mint<MOD> other) const { int32_t c = (int64_t)this->value * other.value % MOD; return mint<MOD>(c < 0 ? c + MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
    inline mint<MOD> & operator -= (mint<MOD> other) { this->value -= other.value; if (this->value <    0) this->value += MOD; return *this; }
    inline mint<MOD> & operator *= (mint<MOD> other) { this->value = (int64_t)this->value * other.value % MOD; if (this->value < 0) this->value += MOD; return *this; }
};
template <int32_t MOD> mint<MOD> operator * (int64_t value, mint<MOD> n) { return mint<MOD>(value) * n; }
template <int32_t MOD> std::ostream & operator << (std::ostream & out, mint<MOD> n) { return out << n.value; }


constexpr int MOD = 1e9 + 7;
mint<MOD> solve(int n, int k) {
    auto dp = make_vectors(n + 1, n + 1, k + 1, mint<MOD>());
    dp[0][0][0] = 1;
    REP (i, n) {
        REP (inout, n + 1) {
            REP (j, k + 1) if (j % 2 == 0 and j + 2 * inout <= k) {
                dp[i + 1][inout][j + 2 * inout] += dp[i][inout][j];  // i -> i
                dp[i + 1][inout][j + 2 * inout] += inout * dp[i][inout][j];  // l -> i -> r
                dp[i + 1][inout][j + 2 * inout] += inout * dp[i][inout][j];  // r -> i -> l
                if (inout - 1 >= 0) dp[i + 1][inout - 1][j + 2 * inout] += inout * inout * dp[i][inout][j];  // l -> i -> l'
                if (inout < n) dp[i + 1][inout + 1][j + 2 * inout] += dp[i][inout][j];  // r -> i -> r'
            }
        }
    }
    return dp[n][0][k];
}

int main() {
    int n, k; cin >> n >> k;
    cout << solve(n, k) << endl;
    return 0;
}


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

int main() {

	int n;
	cin >> n;

	for (int i = 1; i < 10; ++i)
		for (int j = 1; j < 10; ++j) {
			if (i * j == n) {
				cout << "Yes\n";
				return 0;
			}
		}
	cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

mbase = 10000
newtype ModInt = Mod Int deriving (Eq, Ord, Show)
modInt n = Mod (n `mod` mbase)
modIntUnsafe n = Mod n
modzero = Mod 0
modone = Mod 1
getMod (Mod x) = x
instance Num ModInt where
    Mod x + Mod y = modInt (x+y)
    Mod x * Mod y = modInt (fromInteger (toInteger x * toInteger y))
    abs = id
    signum (Mod 0) = 0
    signum (Mod _) = 1
    fromInteger n = Mod (fromInteger (n `mod` toInteger mbase))
    negate (Mod 0) = Mod 0
    negate (Mod x) = Mod (mbase - x)

f n ([1,1]:xs) = g 2 n modone modzero modzero modzero modzero modzero xs
f n ([1,2]:xs) = g 2 n modzero modzero modone modzero modzero modzero xs
f n ([1,3]:xs) = g 2 n modzero modzero modzero modzero modone modzero xs
f n xs = g 2 n modone modzero modone modzero modone modzero xs
g d n t1 t2 c1 c2 b1 b2 []
  | d>n = t1 + t2 + c1 + c2 + b1 + b2
  | otherwise = g (d+1) n (c1+c2+b1+b2) t1 (t1+t2+b1+b2) c1 (t1+t2+c1+c2) b1 []
g d n t1 t2 c1 c2 b1 b2 xa@([y,k]:xs)
  | d>n = t1 + t2 + c1 + c2 + b1 + b2
  | d==y = case k of 
      1 -> g (d+1) n (c1+c2+b1+b2) t1 modzero modzero modzero modzero xs
      2 -> g (d+1) n modzero modzero (t1+t2+b1+b2) c1 modzero modzero xs
      3 -> g (d+1) n modzero modzero modzero modzero (t1+t2+c1+c2) b1 xs
  | otherwise = g (d+1) n (c1+c2+b1+b2) t1 (t1+t2+b1+b2) c1 (t1+t2+c1+c2) b1 xa

main = do
    [n,k] <- getInts
    xs <- sortBy (on compare head) <$> replicateM k getInts
    print $ getMod $ f n xs
    return ()

Measured memory_bytes: 4224
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  int a=0, b=0, c=0;
  for(int i=0;i<S.size();++i) {
    if(S[i]=='a') a++;
    if(S[i]=='b') b++;
    if(S[i]=='c') c++;
  }
  if(b<c) swap(b, c);
  if(a<b) swap(a, b);
  if(b<c) swap(b, c);
  if(a-c>1) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


Measured memory_bytes: 3748
A, B, C, X, Y = map(int, input().split(' '))

max_c = max(2*X, 2*Y)

min_cost = float('inf')
for c in range(0, max_c+1, 2):
  a = max(0, X - c//2)
  b = max(0, Y - c//2)
  cost = A*a + B*b + C*c
  
  if cost < min_cost:
    min_cost = cost
    
    
print(min_cost)

Measured memory_bytes: 9196
#include<iostream>
int main(){
  int x,y,temp;
  while(1){
    std::cin >> x >> y;
    if(!(x || y)) return 0;
    if(x > y){
      temp = x;
      x = y;
      y = temp;
    }
    std::cout << x << " " << y << std::endl;
  }
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=2019;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l,r;
    cin>>l>>r;
    ll x=l/mod;
    ll y=r/mod;
    //cout<<x<<' '<<y<<endl;
    if(x<y){
      cout<<0<<endl;
      return 0;
    }
    l%=mod;
    r%=mod;
    ll ans=2019;
    if(l>=r) r+=2019;
    FOR(i,l,r+1)FOR(j,l,r+1){
      if(i>=j) continue;
      ans=min(ans,(i*j)%mod);
    }
    cout<<ans<<endl;
}

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

int main() {
  int k, a, b;
  string ans = "NG";
  cin >> k >> a >> b;
  for(int i = a; i <= b; i++) {
    if(i % k == 0) {
      ans = "OK";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e7+10,mod=1e9+7,inf=3e18+10;
int n,dif[2],a[M],dp[M][2],ok[M][2],suf[M][2];
int pw(int x,int y)
{
	if(y==0)return 1;
	int tmp=pw(x,y/2);
	if(y%2==0)return (tmp*tmp)%mod;
	return ((tmp*tmp)%mod*x)%mod;
}
void fdp(int i,int j)
{
	//if(abs(a[i+1]-a[i])>=dif[j])dp[i][j]=dp[i+1][j];
	int tmp=a[i]+dif[j];
	int ind=lower_bound(a+1,a+n+2,tmp)-a;
	ind--;
	ind=max(ind,i+1);
	int r=ok[i+1][1-j];
	if(r>=ind)dp[i][j]+=(suf[ind][1-j]-suf[r+1][1-j]+mod)%mod;
	dp[i][j]+=mod;
	dp[i][j]%=mod;
	suf[i][j]=suf[i+1][j];
	suf[i][j]+=dp[i][j];
	suf[i][j]%=mod;
	//cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<ind<<" "<<ok[i+1][1-j]<<endl;
}
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	//int n;
	cin>>n>>dif[0]>>dif[1];
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	a[n+1]=inf;
	dp[n+1][1]=1;
	dp[n+1][0]=1;
	suf[n+1][0]=1;
	suf[n+1][1]=1;
	ok[n+1][1]=n+1;
	ok[n+1][0]=n+1;
	a[0]=-inf;
	for(int i=0;i<=1;i++)
	{
		for(int j=n;j>=1;j--)
		{
			ok[j][i]=j;
			if(abs(a[j+1]-a[j])>=dif[i])ok[j][i]=ok[j+1][i];
		}
	}
	for(int i=n;i>=0;i--)
	{
		for(int j=0;j<=1;j++)fdp(i,j);
	}
	cout<<((dp[0][0]+dp[0][1])%mod*pw(2,mod-2))%mod;
}	

Measured memory_bytes: 10112
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

char keitai[][6] =
{
	".,!? ",	
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};

char out_keitai(int num, int count) {
	if (num == 1) {
		if (count%5 != 0) {
			return keitai[num-1][(count%5)-1];
		}else {
			return keitai[num-1][4];
		}
	}else if (num == 7 || num == 9) {
		if (count%4 != 0) {
			return keitai[num-1][(count%4)-1];
		}else {
			return keitai[num-1][3];
		}
	}else {
		if (count%3 != 0) {
			return keitai[num-1][(count%3)-1];
		}else {
			return keitai[num-1][2];
		}
	}
}
int main(void) {
	int n;
	char inp;
	std::string str;

	getline(cin, str);
	n = atoi(str.c_str());

	for (int i = 0; i < n; i++) {
		getline(cin, str);
		int num;
		int count = 0;
		for (int j = 0; j < str.length(); j++) {
			std::string dstr;
			dstr = str.substr(j,1);
			num = atoi(dstr.c_str());
			if (num != 0) {
				count++;
				int seq = 1;
				int next_num;
				while (seq) {
					dstr = str.substr(j+1,1);
					next_num = atoi(dstr.c_str());
					if (num == next_num) {
						count++;
						j++;
					}else {
						seq = 0;
						cout << out_keitai(num,count);
						count = 0;
					}
				}	
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, h, w;
    cin>>n>>h>>w;
    cout<<(n - h + 1) * (n - w + 1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

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

int gcd(vector<int> A)
{
    int ans = A.at(0);
    for (int i = 1; i < A.size(); i++)
    {
        ans = gcd(ans, A.at(i));
    }
    return ans;
}

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v.at(i);
    cout << gcd(v) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
pii mon[200009];
int N,D,A;
int pos[200009];
ll sum[200009];
int main()
{
    scanf("%d%d%d",&N,&D,&A);
    for(int i=1;i<=N;i++)scanf("%d%d",&mon[i].first,&mon[i].second),pos[i]=mon[i].first;
    sort(pos+1,pos+1+N);sort(mon+1,mon+N+1);
    ll ans=0;
    for(int i=1;i<=N;i++)
    {
        sum[i]+=sum[i-1];
        mon[i].second+=sum[i];
        if(mon[i].second<=0)continue;
        int ppos=upper_bound(pos+1,pos+1+N,mon[i].first+2*D)-pos;
        int t=(mon[i].second+A-1)/A;
     //   cout<<i<<" "<<t<<" "<<ppos<<endl;
        ans+=t;
        sum[i]-=1ll*t*A;
        sum[ppos]+=1ll*t*A;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

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

		int n = scanner.nextInt();
		int a = scanner.nextInt();
		int b = scanner.nextInt();

		if (a > b) {
			System.out.print(b);
		} else {
			System.out.print(a);
		}
		System.out.print(" ");
		if (n >= a + b) {
			System.out.print("0");
		} else {
				System.out.print((a + b) - n);
		}

		scanner.close();
	}

}

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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    int ans = 0;
    rep(i,N){
        ans += vec[i] - 1;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
from itertools import accumulate
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    N, K = map(int, input().split())
    Ps = list(map(lambda x: int(x)-1, input().split()))
    Cs = list(map(int, input().split()))

    cycless = [[] for _ in range(N)]
    useds = [0] * N
    for no in range(N):
        if useds[no]: continue
        x = no
        while True:
            useds[x] = 1
            cycless[no].append(Cs[x])
            x = Ps[x]
            if x == no:
                break

#    for no in range(N):
#        print('# no:', no, '/ cycless[no]:', cycless[no], file=sys.stderr)

    ans = -float('inf')
    for no in range(N):
        if not cycless[no]: continue
        L = len(cycless[no])
        accCycles = list(accumulate([0]+cycless[no]+cycless[no]+cycless[no]))
        sumC = sum(cycless[no])
#        print('\n# no:', no, '/ sumC:', sumC, file=sys.stderr)
        if sumC > 0:
            num = K//L
            if num > 0:
                num -= 1
                if num == 0:
                    fr = 1
                else:
                    fr = 0
                score = -float('inf')
                for M in range(fr, (L + K%L)+1):
                    for st in range(L):
                        s = accCycles[st+M] - accCycles[st]
                        if s > score:
                            score = s
                score += sumC * num
            else:
                score = -float('inf')
                for M in range(1, K+1):
                    for st in range(L):
                        s = accCycles[st+M] - accCycles[st]
                        if s > score:
                            score = s
        else:
            score = -float('inf')
            for M in range(1, (K if K <= L else L)+1):
                for st in range(L):
                    s = accCycles[st+M] - accCycles[st]
                    if s > score:
                        score = s
        if score > ans:
            ans = score
#        print('# no:', no, '/ score:', score, file=sys.stderr)

    print(ans)


solve()


Measured memory_bytes: 69320
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

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

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main()
{
	ll  i, j, k, l, m, sum, flag, N, x, y, M, K, H, W, B;
	cin >> K;
	vector<ll>A(K);
	REP(i, 0, K) {
		cin >> A[i];
	}
	ll min, max;
	reverse(A.begin(), A.end());
	if (A[0] != 2) {
		output("-1");
		return 0;
	}
	min = max = 2;
	REP(i, 1, K) {
		if (max + A[i - 1] - 1 - min >= A[i]) {
			if (min%A[i] != 0)
				min = min + A[i] - min % A[i];
			else
				min = min;

			max = (max + A[i - 1] - 1)/A[i]*A[i] ;
			//output(min); output(max);
		}
		else if (min%A[i] == 0) {
			min = min ;

			max = (max + A[i - 1] - 1) / A[i] * A[i];
			//output(min); output(max);
		}
		else if (min%A[i] > (max + A[i - 1] - 1) % A[i]) {
			min = min + A[i] - min % A[i];

			max = (max + A[i - 1] - 1) / A[i] * A[i];
			//output(min); output(max);
		}
		else {
			output("-1");
			return 0;
		}
	}
	max = max + A[K - 1] - 1;
	output(min);
	output(max);
	
}













Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

    int ans = 0;

    for (int i = 1; i < N - 1; i++){
        map <int, int> M1, M2;
        for (int j = 0; j < i; j++){
            M1[S[j]] ++;
        }
        for (int j = i; j < N; j++){
            M2[S[j]] ++;
        }

        int count = 0;

        for (int j = 'a'; j <= 'z'; j++){
            if (M1[j] > 0 && M2[j] > 0){
                count ++;
            }
        }
        
        if (ans < count){
            ans = count;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1]==s[2])
    cout << "Yes" << endl;
  else if (s[1]==s[2] && s[2]== s[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List

main :: IO ()
main = do
    n <- read <$> getLine
    ls <- map (map read . words) <$> replicateM n getLine
    mapM_ putStrLn $ solve ls

solve :: [[Int]] -> [String]
solve [] = []
solve (x:xs) = (isRT $ sort x):(solve xs)
    where
        isRT :: [Int] -> String
        isRT [a,b,c] = if a^2 + b^2 == c^2
                           then "YES"
                           else "NO"

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp[28],data,m,h,w,x,y,xcmp,ycmp,sum=0,alpa[28];

string s;

vector<int> z;

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

        cin >> n;
        rep(i,27){
            alpa[i]=1000;
        }
        rep(i,n){
            cin >> s;
            rep(k,27){
                cmp[k]=0;
            }
            rep(j,s.size()){
                cmp[s[j]-'a']++;
            }
            rep(j,26){
                alpa[j]=min(alpa[j],cmp[j]);
            }
        }
        
        rep(i,26){
            rep(j,alpa[i]){
                cout << (char)('a'+i);
            }
        }
        cout << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[22][1<<21],a[22][22];
int lowbit(int x)
{
	return x&(-x);
}
int count1(int num)
{
	int ret=0;
	while(num)
	{	
		ret++;
		num-=lowbit(num);
	}
	return ret;
}
int main()
{
	int n,i,j,l;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	f[0][0]=1;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<1<<n;j++)
		{
			if(count1(j)==i)
				for(l=0;l<n;l++)
				{
					if((j&(1<<l))&&a[i][n-l])
					{
						f[i][j]=(f[i][j]+f[i-1][j^(1<<l)])%1000000007;
					}
				}
		}
	}
	printf("%d",f[n][(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 162048
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 100005


int main(){


    ll n,x;
    cin >> n >> x;
    vector<ll> a(ARRAY_MAX,0);
    REP(i,n){
        cin >> a[i];
    }

    ll ans = 0;
    ll tmp = 0;
    REP(i,n){
        
        if(tmp + a[i] > x){
            //cout << i << " a " << tmp+a[i]-x << endl;
            ans += tmp+a[i]-x;
            a[i] = a[i] - (tmp+a[i]-x);
            tmp = a[i];
            if(a[i] > x){
                ans += a[i]-x;
                a[i] = x;
                tmp = a[i];
            }
        }else if(a[i] > x){
            ans += a[i]-x;
            a[i] = x;
            tmp = a[i];
        }else{
            tmp = a[i];
        }

    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  string str;
  cin>>str;
  char c='a';
  int i=0; 
  int cnt=0;
  const int l=str.length();
  //cout<<l<<endl;
  while(i<l){
    if(str[i]=='1')	cnt++;
  	i++;  
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int R;
  cin >> R;
  if(R<1200){
    cout<<"ABC"<<endl;
  }else if(R<2800){
    cout<<"ARC"<<endl;
  }else{
    cout <<"AGC"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
Q,H,S,D = map(int,input().split())
N = int(input())
Min = min(4*Q,2*H,S)
if Min > D/2:
    if N%2 == 0:
        print(N//2*D)
    else:
        print(N//2*D + Min)
else:
    print(Min*N)

Measured memory_bytes: 9172
N,X,Y=map(int, input().split())

D=[0]*(N-1)

for i in range(1,N):
  for j in range(i+1,N+1):
    d=min(abs(i-j),abs(X-i)+1+abs(Y-j))
    D[d-1]+=1
    #print(i,j,d)
for i in range(len(D)):
  print(D[i])

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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  if (n % 2) {
    cout << "No";
  } else {
    if (s.substr(0, n / 2) == s.substr(n / 2)) {
      cout << "Yes";
    } else {
      cout << "No";
    }
  }
  return 0;
}


Measured memory_bytes: 3624
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll n;
    cin>>n;
    ll enda=0,beginb=0,ba=0;
    ll ans=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int i=1;i<s.size();i++){
            if(s[i-1]=='A' && s[i]=='B'){ans++;}
        }
        if(s[0]=='B' && s.back()=='A'){ba++;}
        else if(s[0]=='B'){beginb++;}
        else if(s.back()=='A'){enda++;}
    }
    //cout<<ans<<" "<<ba<<" "<<beginb<<" "<<enda<<endl;
    ans+=max(0LL,ba-1);
    if(ba && enda){ans++; enda--;}
    if(ba && beginb){ans++; beginb--;}
    ans+=min(enda,beginb);
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
string s, t, res;
int n, m, j;

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    string res = "~";
    for(int i=0; i<=n-m; ++i) {
        bool tmp = 1;
        string s2 = s;
        for(int j=0; j<m; ++j) {
            if(s[i+j] != '?' && s[i+j] != t[j])
                tmp = 0;
            s2[i+j] = t[j];
        }
        if(tmp) {
            replace(s2.begin(), s2.end(), '?', 'a');
            res = min(res, s2);
        }
    }
 
    if(res == "~")
        cout << "UNRESTORABLE" << endl;
    else
        cout << res << endl;
}

int main() {
    solve();
    return 0;
}

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

from collections import Counter, OrderedDict

a=Counter(a)

if len(a) <= k:
    print(0)
else:
    b = sorted(a.items(), key=lambda pair: pair[1], reverse=True)
    
    ans = 0
    
    for i in b[k:]:
        ans += i[1]

    print(ans)    

Measured memory_bytes: 39004
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9

int main() {
    long long int A;
    string B_str;
    cin >> A >> B_str;


    int B = 100*(B_str[0]-'0') + 10*(B_str[2]-'0') + (B_str[3]-'0');

    if(A==0 || B==0){
        cout << 0 << endl;
        return 0;
    }

    cout << (long long int)((A*B)/100) << endl;
}


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

//降順バブルソート
void bubblesort(int a[],int N){
    for(int i=0; i<N-1; i++){
        for(int j=0; j<N-1; j++){
            if(a[j+1]>a[j]){
                int swap = a[j];
                a[j] = a[j+1];
                a[j+1] = swap;
            }
        }
    }
}


int main(void){

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

    bubblesort(a, N);

    int sum = a[0]/2;
    for (int i=1; i<N; i++) {
        sum += a[i];
    }

    printf("%d\n",sum);

    return 0;
}


Measured memory_bytes: 128
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, A, B = map(int, input().split())
    X = list(map(int, input().split()))

    res = 0
    for i in range(1, N):
        d = (X[i] - X[i - 1]) * A
        if d <= B:
            res += d
        else:
            res += B

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63084
#include <iostream>
#include <fstream>
#include <bits/stdc++.h> 
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int h, a;

int main(){
    IOS;
    cin >> h >> a;
    int attacks = h/a;
    if(!(h % a == 0)){
        attacks++;
    }
    cout << attacks;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int w,a,b;
cin>>w>>a>>b;
if(a<b && b>(a+w)){
    cout<<abs(b-(a+w))<<"\n";
}else if(a>b){
    cout<<abs(a-(b+w))<<"\n";
}
else if(a<=b<=(a+w)){
    cout<<"0 \n";
}
}


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            string[] input2 = Console.ReadLine().Split(' ');

            int SVDays = int.Parse(input1[0]);

            int ADays = 0;

            for(int i = 0; i < int.Parse(input1[1]); i++){
                ADays += int.Parse(input2[i]);
            }
            
            if(ADays <= SVDays){
                Console.WriteLine(SVDays - ADays);
            }else{
                Console.WriteLine("-1");
            }
        }
    }
}


Measured memory_bytes: 28328
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;

int main() {
	int n,k; scanf("%d%d",&n,&k);
	vector<int> v(n);
	for(int i = 0 ; i < n; i++) scanf("%d",&v[i]);
	
	const int nax = 1e9 + 90;
	vector<int> dp(n,nax);
	dp[0] = 0;
	
	for(int i = 0 ; i < n; i++){
		for(int j = 1 ; j <= k ; j++){
			int x = j + i;
			if(x < n )
				dp[x] = min( abs(v[i]-v[x]) + dp[i] , dp[x] );
		}
	}
	printf("%d\n",dp[n-1]);
	return 0;
}


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

int main(){
    ll l,r,d;
    cin>>l>>r>>d;
    cout<<r/d-(l-1)/d<<endl;
    return 0;
}

Measured memory_bytes: 3592
import sys
input = sys.stdin.readline

N = int(input())
A = [0]+list(map(int, input().split()))+[0]
ori = 0

for i in range(N+1):
    ori += abs(A[i+1]-A[i])

for i in range(1, N+1):
    print(ori-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int N;
	cin >> N;
	bool fail=false;
	vector<int> b(N), way(N);
	REP(i, N)cin >> b[i];
	REP(i, N)b[i]--;

	for (int times = N - 1; times >= 0; times--) {
		int r=times;
		for (; r >= 0; r--) {
			if (b[r] == r) {
				way[times] = r;
				b.erase(b.begin() + r);
				break;
			}
		}
		if (r == -1) {
			fail=true;
			break;
		}
	}
	if(fail)cout<<-1<<endl;
	else REP(i, N)cout << way[i] + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n;
string s;
bool flag = false;

int main() {

	cin >> n >> s;

	if (n % 2 == 1) {
		flag = true;
	}
	else {
		rep(i, n / 2) {
			if (s[i] != s[i + n / 2]) {
				flag = true;
				break;
			}
		}
		if (!flag) {
			cout << "Yes" << endl;
		}
	}

	if (flag) {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256