akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;

long long n,k,ans=1e12,l,r,mid,cnt,x;
long long a[MAXN],b[MAXN];

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

int main()
{
 cin >> n >> k;
 for(int i=1;i<=n;i++) cin >> a[i];
 for(int i=1;i<=n;i++) cin >> b[i];
 sort(a+1,a+n+1);
 sort(b+1,b+n+1,cmp);
 for(int i=1;i<=n;i++) r=max(r,a[i]*b[i]);
 while(l<=r)
 {
  mid=(l+r)/2;cnt=0;
  for(int i=1;i<=n;i++)
  {
   if(a[i]*b[i]>mid)
   {
    cnt+=a[i];
    x=mid/b[i];
    cnt-=x;
   }
  } 
  if(cnt<=k)
  {
   ans=min(ans,mid);
   r=mid-1;
  }
  else l=mid+1;
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 3328
use proconio::{input, marker::Usize1};
use std::cell::RefCell;

fn main() {
    input! {
        n: usize, m: u64, q: usize,
        qs: [(Usize1, Usize1, u64, u64); q]
    }
    let sq = RefCell::new(Vec::new());
    let mut dfs = unsafe { std::mem::uninitialized() };
    let rec = { &dfs as *const dyn Fn() -> u64 };
    dfs = || unsafe {
        if sq.borrow().len() == n {
            qs.iter()
                .map(|&(a, b, c, d)| {
                    if sq.borrow()[b] - sq.borrow()[a] == c {
                        d
                    } else {
                        0
                    }
                })
                .sum()
        } else {
            let last = *sq.borrow().last().unwrap_or(&1);
            (last..=m)
                .map(|x| {
                    sq.borrow_mut().push(x);
                    let ret = (*rec)();
                    sq.borrow_mut().pop();
                    ret
                })
                .max()
                .unwrap()
        }
    };
    println!("{}", dfs());
}


Measured memory_bytes: 2192
#include<stdio.h> 
#include<iostream> 
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<bits/stdc++.h>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#define cuttime ios::sync_with_stdio(false)
#define swap(x, y) x ^= y, y ^= x, x^= y
#define INF 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define scan1(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scanll1(x) scanf("%lld",&x)
#define scanll2(x,y) scanf("%lld%lld",&x,&y)
#define scanll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define lowbit(x) (x&(-x))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(x) cout <<#x<<": "<<x<<endl
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+20;
const int MAX=10000007;
inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}
inline void out(ll x) {   
	if(x>9) out(x/10);   
	putchar(x%10+'0'); 
}
ll q[N];
map<ll,ll>mp,vis;
string s="abcdefghijklmnopqrstuvwxyz";
int main(){
	int n;
	n=read();
	ll sum=0;
	rep(i,1,n){
		q[i]=read();
		mp[q[i]]++;
		sum+=q[i];
	}
	int m;
	m=read();
	ll l,r;
	rep(i,1,m){
		scanll2(l,r);
		sum-=mp[l]*l;
		mp[r]+=mp[l];
		sum+=mp[l]*r;
		cout<<sum<<endl;
		mp[l]=0;

	}	
}
/*

 */

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

map<ll, ll> t;
ll turns(ll h)
{
  if (t[h])
    return t[h];
  if (h == 1)
    return 1;
  return t[h] = turns(h / 2) * 2 + 1;
}

int main()
{
  ll h;
  cin >> h;
  cout << turns(h) << endl;
  return 0;
}

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

int main(){

    string s;
    cin >> s;

    int ans=0;

    rep(i,s.size()-1){
        if(s[i]!=s[i+1]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const int TopIndex = 1;
const int DummySize = 1;

void Exchange(vector<int>& Heap, int InsertIndex)
{
	int ParentIndex = InsertIndex / 2;
	while(InsertIndex > TopIndex && Heap[InsertIndex] > Heap[ParentIndex]){
		swap(Heap[InsertIndex], Heap[ParentIndex]);
		InsertIndex = ParentIndex;
		ParentIndex = InsertIndex / 2;
	}
}

void Insert(vector<int>& Heap, int k)
{
	Heap.push_back(k);
	int InsertIndex = Heap.size() - 1;
	Exchange(Heap, InsertIndex);
}

void maxHeapify(vector<int>& A, int i)
{
	int H = A.size() - 1;
	int l = 2 * i;
	int r = 2 * i + 1;
	//????????????????????????????????§???????????§????????????????????¶
	int largest;
	if(l <= H && A[l] > A[i]){
		largest = l;
	}else{
		largest = i;
	}
	if(r <= H && A[r] > A[largest]){
		largest = r;
	}
	//i???????????????????????§????????´???
	if(largest != i){
		swap(A[i], A[largest]);
		//?????°??????????????????
		maxHeapify(A, largest);
	}
}

void ExtractMax(vector<int>& Heap)
{
	int TailIndex = Heap.size() - 1;
	cout << Heap[TopIndex] << endl;
	swap(Heap[TailIndex], Heap[TopIndex]);
	Heap.pop_back();
	maxHeapify(Heap, TopIndex);
}

int main()
{
	vector<int> Heap(DummySize);
	while(true){
		string Command;
		cin >> Command;
		if(Command == "insert"){
			int k;
			cin >> k;
			Insert(Heap, k);
		}else if(Command == "extract"){
			ExtractMax(Heap);
		}else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 6968
#include<bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#define XOX
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

bool istri(int a, int b, int c)
{
    if (a + b <= c) return false;
    if (a + c <= b) return false;
    if (b + c <= a) return false;
    if (a == b || b == c || a == c) return false;
    return true;
}

signed main()
{
    int n;
    cin >> n;
    int l[n];
    for (int i =0; i < n; i++) {
        cin >> l[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                //if (i == j || i == k || j == k) continue;
                cnt += istri(l[i], l[j], l[k]);
            }
        }
    }
    cout << cnt << "\n";
}






























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

object Main extends App {
  val n = readInt()
  val inputs = List.fill(n - 1)(readLine().split(" ").map(_.toInt).toList)

  for (i <- 0 until n - 1) {
    var time = 0
    for (j <- i until n - 1) {
      val c = inputs(j).head
      val s = inputs(j)(1)
      val f = inputs(j)(2)
      if (time < s)
        time = s
      else if (time % f != 0)
        time += f - (time % f)
      time += c
    }
    println(time)
  }

  println(0)
}


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

remain_max = [a[-1]]*n
for i in range(1, n):
    remain_max[-(i+1)] = max(a[-i], remain_max[-i])

diffs1 = [0]*n
for i in range(n):
    diffs1[i] = remain_max[i] - a[i]

max_diff1 = 0
ans1 = 0
for i in range(n):
    if diffs1[i] > max_diff1:
        max_diff1 = diffs1[i]
        ans1 = 1
    elif diffs1[i] == max_diff1:
        ans1 += 1
# print(diffs1, ans1)

remain_min = [a[0]]*n
for i in range(1, n):
    remain_min[i] = min(a[i-1], remain_min[i-1])

diffs2 = [0]*n
for i in range(n):
    diffs2[i] = a[i] - remain_min[i]

max_diff2 = 0
ans2 = 0
for i in range(n):
    if diffs2[i] > max_diff2:
        max_diff2 = diffs2[i]
        ans2 = 1
    elif diffs2[i] == max_diff2:
        ans2 += 1
# print(diffs2, ans2)

print(min(ans1, ans2))
        


Measured memory_bytes: 17244
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
constexpr ll mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

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

    ll sum = 0;
    rep(i, n.size()){
        sum+=n[i]-'0';
    }

    cout<<((sum%9==0) ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
/* #define int long long */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    int r;
    cin >> r;
    cout << 3.141592 * 2 * r << endl;
}

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
typedef long long lint;
using namespace std;

const int MAXC = 33;
const int MAXN = 555;
int D[MAXC][MAXC];
int color[MAXN][MAXN];
int diff[3][MAXC];

int main() {
    int N, C;
    cin >> N >> C;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> color[i][j];
            --color[i][j];
        }
    }
    for (int c = 0; c < C; c++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                const int index = (i+j)%3;
                diff[index][c] += D[color[i][j]][c];
            }
        }
    }
    int ans = 1e9;
    for (int c1 = 0; c1 < C; c1++) {
        for (int c2 = 0; c2 < C; c2++) {
            for (int c3 = 0; c3 < C; c3++) {
                if (c1 == c2 || c2 == c3 || c3 == c1) continue;
                ans = min(ans, diff[0][c1] + diff[1][c2] + diff[2][c3]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
   ll n, k;
   cin >> n >> k;
   vector<ll> a(n);
   rep(i, n)cin >> a[i];
   ll bit[40] = {};
   for(int i=40; i>=0; --i){
       rep(j, n)if((1LL<<i)&a[j])bit[i]++;
   }
   ll x = 0;
   for(int i=40; i>=0; --i){
       if((1LL<<i)>k)continue;
       if(bit[i]<=n/2&&x+(1LL<<i)<=k){
           x += 1LL<<i;
       }
   }
   ll ans = 0;
   rep(i, n)ans+=(a[i]^x);
   cout << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    p = [int(pi) for pi in input().split()]
    cnt = 0
    for i in range(1, n - 1):
        if sorted([p[i - 1], p[i], p[i + 1]])[1] == p[i]:
            cnt += 1

    print(cnt)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29164
L = int(input())
l = L//3
'''
ans = (L//3)**3
if L % 3 == 0:
    print(ans)
    exit()j
elif L % 3 == 1:
    for i in range(1000001):
        for j in range(1000000-i):
            ans=max(ans,ans+l*l*(0.000001*()))
'''
print((L/3)*(L/3)*(L/3))


Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<cinttypes>
#include<limits>
#include<algorithm>
#include<numeric>

//2≤ N ≤10^5
//0≤ a[i] ≤10^9
//0≤ x ≤10^9


using n_type = std::uint32_t;
using a_type = std::int64_t;
using x_type = std::uint32_t;
using veca = std::vector<a_type>;

template<class T>
void print(std::vector<T>& vec) {
	for (const auto&v : vec) {
		std::cout << v << ", ";
	}std::cout << "\n";
}

int main() {
	//std::cout << std::numeric_limits<std::uint32_t>::max() << "\n";
	n_type N{};
	x_type x{};
	std::cin >> N >> x;

	veca v;
	v.reserve(N);
	a_type t1{ 0 };
	for (size_t i{ 0 }; i < N; i++) {
		std::cin >> t1;
		v.push_back(t1);
	}
	//	print(v);
	std::uintmax_t count_{};
	for (size_t i{ 1 }; i < v.size(); i++) {
		std::int64_t t = v[i - 1] + v[i] - x;
		if (t > 0) {
			v[i] = std::max<std::int64_t>(0, (v[i] - t));//
			count_ += t;
		}

		//std::cout << t << ", ";
	}
	//std::cout << "\n";
	std::cout << count_ << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	int n = sz(s);
	string t;
	vi pos;
	rep(i,0,n){
		if(s[i] != 'x'){
			t.push_back(s[i]);
			pos.push_back(i);
		}
	}
	if(sz(t)==0){
		cout << 0 << endl;
		return 0;
	}
	string t2 = t;
	reverse(all(t2));
	if(t2 != t){
		cout << -1 << endl;
		return 0;
	}
	int mi1 = (sz(t)-1)/2;
	int ans = 0;
	rep(i,0,mi1){
		int j = sz(t)-1-i;
		int c1 = pos[i+1]-pos[i];
		int c2 = pos[j]-pos[j-1];
		ans += abs(c1 - c2);
	}
	ans += abs(pos[0] - (n-1 - pos.back()));
	cout << ans << endl;
}

Measured memory_bytes: 1104
package main

import (
	"fmt"
)

func main() {
	var n string
	fmt.Scan(&n)
	ns :=[]rune(n)

	for i, _ := range ns {
		if ns[i] == '1'{
			ns[i] = '9'
		}else if ns[i] == '9' {
			ns[i] = '1'
		}else{
			continue
		}
	}

	ss := string(ns)
	fmt.Println(ss)
}


Measured memory_bytes: 512
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <sstream>

#define ll long long
#define Int ll
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_N 8

Int N;
vector<Vector2> C(MAX_N);


void input() {
  cin >> N;
  loop(n,0,N) cin >> C[n];
  C.resize(N);
}

double distance() {
  double d = 0;
  loop(n,0,N-1) {
    d += (C[n+1] - C[n]).length();
  }
  return d;
}

void solve() {
  sort(span_all(C));
  double d = 0;
  Int p = 0;
  do {
    p++;
    d += distance();
  } while (next_permutation(span_all(C)));
  cout << d / p << endl;
}

int main(void) {
  cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
string s;
signed main() {
	cin >> s;
	reverse(s.begin(), s.end());
	while (1) {
		if (s.size() == 0)break;
		else if (s.substr(0, 5) == "maerd")s = s.substr(5, s.size() - 5);
		else if (s.substr(0, 7) == "remaerd")s = s.substr(7, s.size() - 7);
		else if (s.substr(0, 5) == "esare")s = s.substr(5, s.size() - 5);
		else if (s.substr(0, 6) == "resare")s = s.substr(6, s.size() - 6);
		else {
			cout << "NO" << endl;
			endre;
		}
	}
	cout << "YES" << endl;
	endre;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long[] l = new long[100001];
        long count = 0;
        for(int i = 0;i < N;i++)    l[sc.nextInt()] += sc.nextLong();
        for(int i = 0;i < 100001;i++){
            count += l[i];
            if(count >= K){
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 88420
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
 
const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
 
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

////////////////////////////////////////////////////////////

int main(){
  long N , M;
  
  cin >> N >> M;

  if(abs(N - M) >= 2 ){
    //P("A done");
    cout << "0" << endl;
  }
  else if(abs(N - M) == 1){
    //P("B done");
    unsigned long ans = max(N,M);
    unsigned long long A = 1 ;
    
    for(unsigned long i = ans ; i >= 1 ; i-- ){
      A  = ( A * i ) % 1000000007;
    }
    
    ans = min(M,N);

    for(unsigned long i = ans ; i >= 1 ; i-- ){
      A = (A * i) % 1000000007;
    }
    

    //P(A);
    cout << A << endl;
    
  }
  else{
    unsigned long ans = max(N,M);
    unsigned long long A = 1;
    //P("C done");

    for(unsigned long i = ans ; i >= 1 ; i-- ){
      A  = ( A * i ) % 1000000007;
    }
    
    for(unsigned long i = ans ; i >= 1 ; i-- ){
      A = (A * i) % 1000000007;
    }
    

    //P(A);
    A = (A * 2) % 1000000007;
    cout << A << endl;
    
  }
    
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

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

int main()
{
  	string n;
  	cin>>n;
  	long long s=0;
  	for(long long i=0; i<n.length(); i++)
    {
      	s+=(n[i]-'0');
    } 
  	if(s%9==0)
      cout<<"Yes\n";
  	else
      cout<<"No\n";
}  

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repl(i, a, b) for (ll i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = b; i >= (a); --i)
#define repdl(i, a, b) for (ll i = b; i >= (a); --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1'000'000'007LL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll x[200005], y[200005];
int main() {
  IOS;
  int n; cin >> n;
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  ll ans = 0, mn, cur;
  for (int p : {1, -1}) {
    for (int q : {1, -1}) {
      mn = p * x[0] + q * y[0];
      for (int i = 1; i < n; i++) {
        cur = p * x[i] + q * y[i];
        ans = max(ans, cur - mn);
        mn = min(mn, cur);
      }
    }
  }
  cout << ans << endl;
}


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

#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod = 1e9+7;
ll INF = 1e17;

int main()
{
    int n,i,cnt=0,minm;
    cin>>n;

    int A[n];
    for(i=0;i<n;i++)
        cin>>A[i];
    
    minm=n+1;
    for(i=0;i<n;i++)
    {
        minm=min(minm,A[i]);
        if(minm>=A[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


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

int main(){
  int N,Q;
  string S;
  cin >> N >> S >> Q;
  vector<set<int>> A(26);
  rep(i,N){
    A.at(S.at(i)-'a').insert(i+1);
  }
  rep(i,Q){
    int t;
    cin >> t;
    if(t==1){
      ll j;
      char c;
      cin >> j >> c;
      A.at(S.at(j-1)-'a').erase(j);
      S.at(j-1)=c;
      A.at(c-'a').insert(j);
    }else{
      int l,r,ans=0;
      cin >> l >> r;
      rep(j,26){
        auto it=A.at(j).lower_bound(l);
        if(A.at(j).end()!=it&&*it<=r) ans++;
      }
      cout << ans << endl;
    }
  }    
}


Measured memory_bytes: 24196
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int n; std::cin >> n;
    std::cout << n * n * n << std::endl;
    return 0;
}

Measured memory_bytes: 256
/*Mrc01*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define endl "\n"
#define mp make_pair
#define pb push_back
#define bit(x, i) (x >>(i - 1) & 1ll)
#define MAX 1000001
const int mod=1000000007;
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<ll int,ll int>,null_type, less<pair<ll int,ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
      new_data_set;
vector<ll int > v[1000100],check;
ll int a[1000010],vis[1000100]; 

void dfs(ll int vtx,ll int count)
{
   ll int f=0;
   vis[vtx]=1;
   count++;
   for(ll int i:v[vtx])
   {
     if(vis[i]!=1)
     {
       f=1;
       dfs(i,count);
     }
   }
   if(f==0)
   {
     check.pb(count-1);
   }
}
void solve()
{  
   ll int n,m;
    cin>>n>>m;
   n--,m--;
   cout<<((n*(n+1))/2)+((m*(m+1))/2);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // ll int t;
    //  cin>>t;
    // while(t--)
    { 
       solve();
    }
}


Measured memory_bytes: 24960
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll test[1234567];
signed main() {
	ll n, m, k; cin >> n >> m >> k;
	rep(i, k) {
		if (i % 2 == 0) {
			if (n % 2 == 1) { n--; }
			m += n / 2; n /= 2;
		}
		else {
			if (m % 2 == 1) { m--; }
			n += m / 2; m /= 2;
		}
	}
	cout << n << ' ' << m << endl;
	return 0;
}

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


def main():
  s = input().strip()
  n = len(s)
  ans = [s[0]]
  i = 1
  while i < n-1:
    if ans[-1] != s[i]:
      ans.append(s[i])
      i += 1
    else:
      ans.append(s[i:i+2])
      i += 2
  if i == n-1:
    if ans[-1] != s[-1]:
      ans.append(s[-1])
    else:
      ans[-1] += s[-1]

  print(len(ans))


if __name__ == '__main__':
  main()


Measured memory_bytes: 8068
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

ll mod(ll a)
{
	if(a<inf)return a;
	else 
	return a%inf;
}
 void test_cases()
{

ll n;
cin>>n;
ll ans=1;
for(ll i=1;i<=n;i++)ans*=i,ans=mod(ans);

cout<<ans;
}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
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;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> sum(n - 1);
  rep(i, n - 1) sum[i] = a[i] + a[i + 1];
  ll ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (sum[i] <= x)
      continue;
    else {
      int d = min(a[i + 1], sum[i] - x);
      ans += d;
      sum[i] -= d;
      sum[i + 1] -= d;
    }
  }
  if (sum[0] > x) {
    int d = sum[0] - x;
    sum[0] -= d;
    ans += d;
  }
  if (sum[n - 2] > x) {
    int d = sum[n - 2] - x;
    sum[n - 2] -= d;
    ans += d;
  }
  cout << ans << endl;
}
int main(void) { solve(); }

Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) par[i] = i;
  }

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

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (sizes[x] > sizes[y]) swap(x, y);

    par[x] = y;
    sizes[y] += sizes[x];
  }

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

  int size(int x) {
    return sizes[find(x)];
  }
};

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

  int N, M, K; cin >> N >> M >> K;
  UnionFind uf(N);
  Graph g(N);
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; a--; b--;
    uf.unite(a, b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  Graph h(N);
  for (int i = 0; i < K; i++) {
    int c, d; cin >> c >> d; c--; d--;
    h[c].push_back(d);
    h[d].push_back(c);
  }
  for (int x = 0; x < N; x++) {
    int ans = uf.size(x) - g[x].size();
    for (int y : h[x]) if (uf.same(x, y)) ans--;
    cout << ans - 1;
    if (x < N-1) cout << " ";
  }
  cout << "\n";
}

Measured memory_bytes: 12664
#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; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 673;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
	string s;
	cin >> s;
	
	int n = s.length();
	
	vi a(n,0);
	
	int temp = 1;
	
	for(int i = n-1;i>=0;i--)
	{
		if(i != n-1) a[i] = a[i+1];
		a[i] = (a[i] + ((s[i] - '0')*temp))%MOD;
		
		temp=(temp*10)%MOD;
	}
	
	vi b(n,0);
	
	for(int i=n-1;i>=0;i--)
	{
		if(i != n-1) b[i] = b[i+1];
		b[i] = (b[i] +  s[i] - '0')%3;
	}
	
	map<pair<int,int>,int> mp;
	
	int res = 0;
	
	mp[{b[0],a[0]}]++;
	
	for(int i=0;i<n;i++)
	{
		int n3 = 0;
		if(i != n-1) n3 = b[i+1];
		
		int nn = 0;
		if(i != n-1) nn = a[i+1];
		
		res+=mp[{n3,nn}];
		mp[{n3,nn}]++;
	}
	
	cout << res;
	
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 6788
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n, k; cin >> n >> k;
	ll cnt = 1;
	for (int i = 0; i < n; i++) {
		if (cnt * 2 < cnt + k) cnt *= 2;
		else cnt += k;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3556
/*
	https://www.youtube.com/watch?v=766qmHTc2ro
*/
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define ull unsigned long long
#define ll long long
#define ss string
#define vt vector
#define pii pair <int,int>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define pll pair <ll,ll>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define sz(x) (int) x.size()
#define bcc __builtin_popcount
#define bll __builtin_popcountll
void ___(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void data(){
	freopen("name.in","r",stdin);
	freopen("name.out","w",stdout);
}
const int N = 3e5 + 500;
const ll INF = 1e18;
const int mod = 1e9 + 7;


int main()
{
	//data();
	___();
	
	
	int n,x,t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t << "\n";
	
	
	return 0;
}




Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5+5;
set<LL> s;
LL dp[100005][2];

int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        LL n,k;
        cin >> n >> k;
        for(int i = 1 ; i <= n ; i++)
        {
                LL x;
                cin >> x;
                s.insert(x);
        }
        dp[0][0] = 1;
        dp[0][1] = 1;
        for(int i = 1 ; i <= k ; i++)
        {
                if(i < *(s.begin()))
                {
                        dp[i][0] = 0;
                        dp[i][1] = 1;
                }
                else
                {
                       // cout << i << ":";
                        LL x = 0;
                        for(auto it:s)
                        {
                                if(i - it < 0) break;
                                LL temp = i - it;
                               // cout << temp << " ";
                                if(temp == 0)
                                {
                                        x = 1;
                                        break;
                                }
                                x = x | dp[temp][1];
                        }
                        if(x == 0)
                        {
                                dp[i][0] = 0;
                                dp[i][1] = 1;
                        }
                        else
                        {
                                dp[i][0] = 1;
                                dp[i][1] = 0;
                        }
                }
               // cout << endl;
        }
        // for(int i = 1 ; i <= k ; i++)
        // {
        //         cout << dp[i][0] << " " << dp[i][1] << endl;
        // }
        if(dp[k][0] == 1)
        {
                cout << "First" << endl;
        }
        else cout <<"Second" << endl;
        return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int a;
int b;

int main(){
	cin >> a;
	b = a / 100;
	a %= 100;
	if (a > 0 && b > 0 &&  a <= 12 && b <= 12){
		cout << "AMBIGUOUS" << endl;
	}
	else if (a > 0 && a <= 12){
		cout << "YYMM" << endl;
	}
	else if (b > 0 && b <= 12){
		cout << "MMYY" << endl;
	}
	else{
		cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

string s, t;
llong nex[32][200005];

int main() {
    
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++){
        nex[s[i] - 'a'][i] = i;
    }

    llong n = s.size();
    for (llong k = 0; k < 32; k++) {
        llong indx = -1;

        for (llong j = n - 1; j >= 0; j--) {
            nex[k][j] = indx;
            
            if (s[j] - 'a' == k) indx = j;
        }

        for (llong j = n - 1; j >= 0; j--) {
            nex[k][j] = indx;
            if (s[j] - 'a' == k) indx = j;
        }
    }

    llong ans = 0;
    llong indx = nex[t[0] - 'a'][n - 1];
    if (indx == -1) {cout << -1 << endl; return 0;}
    for (int i = 1; i < t.size(); i++) {
        llong nindx = nex[t[i] - 'a'][indx];

        if (nindx <= indx) ans += n;

        indx = nindx;
        if (indx == -1) {cout << -1 << endl; return 0;}
    }

    ans += indx + 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 49024
n,k=gets.split.map{|e| e.to_i}
x=gets.split.map{|e| e.to_i}
hs=Hash.new(0)
x.each{|e|
	hs[e]+=1
}
arr=[]
hs.each{|k,v|
	arr<<[v,k]
}
arr.sort!
if arr.size<=k
	puts 0
else
	ans=0
	(0..(arr.size-k-1)).each{|i|
		ans+=arr[i][0]
	}
	puts ans
end

Measured memory_bytes: 40072
import sys
sys.setrecursionlimit(100000000)
 
moves = [(0, -1), (0, 1), (-1, 0), (1, 0)]
 
 
def search(dataset):
    min_time = 0
    mouse = 1
    gx, gy = get_start(dataset)
    for i in xrange(N):
        gx, gy, min_time_tmp = bfs(dataset, (gx, gy), mouse)
        mouse += 1
        min_time += min_time_tmp
    print min_time
 
 
def bfs(dataset, start, mouse):
    INF = 10000000
    min_time = [[INF for j in xrange(W)] for i in xrange(H)]
    min_time[start[0]][start[1]] = 0
    queue = [start]
 
    while len(queue) != 0:
        dx, dy = queue.pop(0)
        for i, j in moves:
            nx = dx + i
            ny = dy + j
            if 0 <= nx < H and 0 <= ny < W and dataset[nx][ny] != 'X' and min_time[nx][ny] == INF:
                cell = dataset[nx][ny]
            else:
                continue
            if type(cell) is int:
                if mouse == int(cell):
                    min_time[nx][ny] = min_time[dx][dy] + 1
                    return nx, ny, min_time[nx][ny]
            min_time[nx][ny] = min_time[dx][dy] + 1
            queue.append((nx, ny))
 
 
def get_start(dataset):
    for i in xrange(H):
        rows = dataset[i]
        for j in xrange(W):
            cell = rows[j]
            if cell == 'S':
                return i, j
 
 
dataset = []
while True:
    line = raw_input().rstrip().split()
    if len(line) == 3:
        H, W, N = map(int, line)
    else:
        row = []
        for e in line[0]:
            if e.isdigit():
                row.append(int(e))
            else:
                row.append(e)
        dataset.append(row)
    if len(dataset) == H:
        search(dataset)
        break

Measured memory_bytes: 32804
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int R = sc.nextInt();
    
   int ans = R;
   if(N<10) ans +=(10-N)*100; 
   System.out.print(ans);
 }
}

Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>

using namespace std;

int n;
string s[2];
//
//
//
long long int solve(int m, long long int ans, int before){
	if(m == n)
		return ans;
	if(s[0][m] == s[1][m]){
		if(before == 1){
			return solve(m + 1, (ans * 2) % 1000000007, 1);
		}
		if(before == 2){
			return solve(m + 1, ans, 1);
		}
		if(before == 0){
			return solve(m + 1, ans * 3, 1);
		}
	}
	else{
		if(before == 1){
			return solve(m + 2, (ans * 2) % 1000000007, 2);
		}
		if(before == 2){
			return solve(m + 2, (ans * 3) % 1000000007, 2);
		}
		if(before == 0){
			return solve(m + 2, ans * 6, 2);
		}
	}
}

int main(){
	cin >> n;
	cin >> s[0] >> s[1];
	
	cout << solve(0, 1, 0) << endl;
	
	return 0;
}

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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

const int _n = 1e6 + 10;
vector<int> Fact(_n), Inv(_n);
const int kmod = 1000000007;

int mul(int a, int b, int mod = kmod)
{
    return (long long)a * b % mod;
}

int add(int a, int b, int mod = kmod)
{
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b, int mod = kmod)
{
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int power(int base, int index, int mod = kmod)
{
    if (index == 0)
        return 1;
    int temp = power(base, index / 2, mod);
    temp = mul(temp, temp, mod);
    if (index & 1)
        temp = mul(temp, base, mod);
    return temp;
}

int mod_inv(int x, int mod = kmod)
{
    return power(x, kmod - 2);
}

void pre()
{
    Fact[0] = 1;
    for (int i = 1; i < _n; ++i)
        Fact[i] = mul(Fact[i - 1], i);
    Inv[_n - 1] = mod_inv(Fact[_n - 1]);
    for (int i = _n - 2; i >= 0; --i)
        Inv[i] = mul(Inv[i + 1], (1 + i));
}

int ncr(int n, int r)
{
    if (n < 0 || r < 0 || n - r < 0)
        return 0;
    return mul(Fact[n], mul(Inv[r], Inv[n - r]));
}

int npr(int n, int r)
{
    if (n < 0 || r < 0 || n - r < 0)
        return 0;
    return mul(Fact[n], Inv[n - r]);
}

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        pre();
        int n, m;
        cin >> n >> m;
        int ret = 0;
        for (int common_numbers = 0; common_numbers <= n; common_numbers++)
        {
            int curr = 1;
            curr = ncr(m, common_numbers);
            // Pick Common numbers
            curr = mul(curr, npr(n, common_numbers));
            // Pick positions for common numbers
            curr = mul(curr, npr(m - common_numbers, n - common_numbers));
            curr = mul(curr, npr(m - common_numbers, n - common_numbers));
            //Pick numbers that are not common
            db(ret, n, m, common_numbers, curr);
            if (common_numbers & 1)
                ret = sub(ret, curr);
            else
                ret = add(ret, curr);
        }
        cout << ret << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 11004
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>

#include<queue>

using namespace std;

int main() {

	int N;
	cin >> N;

	vector<int> vNum(N, 0);

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

	sort(vNum.begin(), vNum.end());
	reverse(vNum.begin(), vNum.end());

	int A = vNum[0];
	int B = 0;
	for (int i = 1; i < N; i++)
	{
		B += vNum[i];
	}


	cout << ((A >= B) ? "No" : "Yes") << endl;

	return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int A, B, T;
    cin >> A >> B >> T;
    int t = A;
    int ans = 0;
    while(t<T+0.5){
        ans += B;
        t += A;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256