akhauriyash/Code-Regression huggingface dataset:
T = int(input())

for t in range(T):
    N, A, B, C, D = map(int, input().split())
    memo = {}

    def dist(n):
        if n == 0:
            return 0
        if n == 1:
            return D
        if n in memo:
            return memo[n]
        
        ret = min(
            D * n,
            D * abs(n - n//5*5) + C + dist(n//5),
            D * abs(n - (n+4)//5*5) + C + dist((n+4)//5),
            D * abs(n - n//3*3) + B + dist(n//3),
            D * abs(n - (n+2)//3*3) + B + dist((n+2)//3),
            D * abs(n - n//2*2) + A + dist(n//2),
            D * abs(n - (n+1)//2*2) + A + dist((n+1)//2)
        )

        memo[n] = ret
        return ret
    print(dist(N))

Measured memory_bytes: 10904
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  lint N;
  cin >> N;
  lint A[N];
  rep(i,N) cin >> A[i];
  lint Asum=0,Bsum=accumulate(A,A+N,0LL);
  lint ans=LINF;
  rep(i,N){
    Asum+=A[i];
    Bsum-=A[i];
    ans=min(ans,llabs(Asum-Bsum));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define sc(x) scanf("%d", &x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define fastio ios::sync_with_stdio(0),cin.tie(0)
template<class T>T gcd(T a, T b){return b?gcd(b, a%b):a;}

int main()
{
    double x, y;
    scanf("%lf%lf", &x, &y);
    printf("%.10f\n", x/y);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<random>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;

string func(string a, string b, int n){
  int x = 0;
  int y = 0;
  // cerr << a << " " << b << endl;
  for(int i=0; i<n; i++){
    // cerr << y << " " << x << endl;
    x += a[i]-'0';
    x *= 10;
    y += b[i]-'0';
    y *= 10;
  }
  x /= 10;
  y /= 10;
  // cerr << y << " " << x << endl;
  return to_string(y - x);
}

int main(void) {
  string n; int l;
  while(cin >> n >> l){
    if( n == "0" && l == 0 ) break;
    int cnt = 0;
    vector<string> ans;
    ans.push_back(n);
    bool f = false;
    while(true){
      while( n.size() != l ) n += '0';
      // cerr << n << " ";
      f = false;
      sort(n.begin(), n.end());
      string n1 = n;
      reverse(n.begin(), n.end());
      string n2 = n;
      n = func(n1, n2, l);

      for(int i=0; i<ans.size(); i++){
        if( n == ans[i] ){
          cout << i << " " << ans[i] << " " << cnt - i + 1 << endl;
          f = true;
          break;
        }
      }
      if( f ) break;

      ans.push_back(n);
      cnt++;
    }

  }

  return 0;
}





// EOF

Measured memory_bytes: 3252
#include <iostream>

using namespace std;
int main() {
    char a;
    char b;
    int ai = 0;
    int bi = 0;
    char S[4];
    cin >> S;
    for (int i=0; i<4; i++) {
        if (ai==0) {
            a = S[i];
            ai++;
        }
        else if (a == S[i]) ai++;
        else if (bi==0) {
            b = S[i];
            bi++;
        }
        else if (b == S[i]) bi++;
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    if (ai == 2 && bi == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#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())
#define fi first
#define se second

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=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,x;
    cin>>k>>x;
    FOR(i,max(-1000000,x-k+1),min(1000001,x+k)){
      cout<<i<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 256
S = [int(s) for s in input()]

start_with0 = [0 if i % 2 else 1 for i in range(len(S))]
start_with1 = [1 if i % 2 else 0 for i in range(len(S))]

diff_0 = sum([i != j  for i, j in zip(S, start_with0)])
diff_1 = sum([i != j  for i, j in zip(S, start_with1)])
print(min(diff_0, diff_1))

Measured memory_bytes: 6300
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) repi(i,0,n)
#define mp make_pair
#define pb push_back

int w, h;
struct node {
  int cst, state, x, y;
  bool operator<(const node &o) const {
    return cst > o.cst;
  }
};

const int MAX = 64;
int f[MAX][MAX];
bool inrange(int x, int y) {
  return x >= 0 && y >= 0 && x < w && y < h;
}
int main()
{
  while(cin >> w >> h, w||h) {
    rep(i, h) rep(j, w) {
      char c;
      cin >> c;
      if(c == 'X') f[j][i] = -1;
      else if(c == 'S' || c == 'T') f[j][i] = 0;
      else f[j][i] = c-'0';
    }
    
    priority_queue<node> pq;
    rep(j, w) if(f[j][h-1] == 0) {
      pq.push((node){0, 1, j, h-1});
      pq.push((node){0, -1, j, h-1});
    }
    set<pair<pair<int, int>, int> > done;
    int ans = -1;
    while(pq.size()) {
      int cst = pq.top().cst;
      int state = pq.top().state;
      int x = pq.top().x;
      int y = pq.top().y;
      pq.pop();
      pair<pair<int, int>, int> key = mp(mp(x, y), state);
      if(done.find(key) != done.end()) continue;
      done.insert(key);
      //      cout << x << " " << y << " " << cst << " " << state << endl;
      if(f[x][y] == 0 && y == 0) {
	ans = cst;
	break;
      }
      repi(i, 1, 4) repi(j,-2, 3) {
	int nx = x+state * i, ny = y+j;
	if(inrange(nx, ny) && f[nx][ny] != -1 && abs(x-nx) + abs(y-ny) <= 3) pq.push((node){cst+f[nx][ny], -state, nx, ny});
      }
      
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1380
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int A[N];
    //2~NなのでN-1個
    for(int i = 0; i < N-1; ++i) cin >> A[i];
    
    map<int,int> m;

    for(int i = 0; i < N-1; ++i){
        //key add
        if(m.count(A[i]) == 0) m.insert(make_pair(A[i],1));
        //value++
        else m[A[i]] = ++m[A[i]];
    }

    for(int i = 1; i <= N; ++i){
        if(m.count(i) == 0) cout << 0 << endl;
        else cout << m[i] << endl;
    }
}

Measured memory_bytes: 13784
require 'prime'
include Math
def max(a,b);                    a > b ? a : b                            end
def min(a,b);                    a < b ?  a : b                           end
def swap(a,b);                   a, b = b, a                              end
def gif;                         gets.to_i                                end
def gsf;                         gets.chomp                               end
def gi;                          gets.split.map(&:to_i)                   end
def gs;                          gets.chomp.split.map(&:to_s)             end
def gc;                          gets.chomp.split('')                     end
def pr(num);                     num.prime_division                       end
def putall(obj);                 obj.each{|o| puts(o)}                    end
def array(size,init=nil);        Array.new(size){init}                    end
def darray(size1,size2,init=nil);Array.new(size1){Array.new(size2){init}} end
def rep(num);                    num.times {|i|yield(i)}                  end
def repl(st,en);                 st.upto(en) {|i|yield(i)}                end


o = gc
e = gc
str = []
loop{
	str << o.shift unless o.empty?
	str << e.shift unless e.empty?
	break if o.empty? && e.empty?
}

puts str.join




Measured memory_bytes: 2044
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

LL a[200005];
LL b[200005];
LL pre_a[200005];
LL pre_b[200005];

int main() {
    LL n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pre_a[i] = pre_a[i - 1] + a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        pre_b[i] = pre_b[i - 1] + b[i];
    }
    int ta = 0;
    for (int i = 0; i <= n; i++) {
        if (pre_a[i] <= k) {
            ta = i;
        }
    }
    int tb = 0;
    for (int i = 0; i <= m; i++) {
        if (pre_b[i] + pre_a[ta] <= k) {
            tb = i;
        }
    }
    int ans = ta + tb;
    ta--;
    for (; ta >= 0; ta--) {
        while (pre_b[tb] + pre_a[ta] <= k && tb <= m) {
            ans = max(ans, ta + tb);
            tb++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;cin >> n;
    vector<int> a(n);
    int ma=0,ma2=0;
    rep(i,n){
        cin >> a[i];
        if(ma<a[i]){
            ma2 = ma;
            ma = a[i];
        }else if(ma2<a[i]){
            ma2 = a[i];
        }
    }
    //cout << "+++ --- +++ --- " << endl;
    rep(i,n){
        if(a[i]==ma){
            cout << ma2 << endl;
        }else{
            cout << ma << endl;
        }
    }
}

Measured memory_bytes: 2432
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
s = input()
print(s[:3])


Measured memory_bytes: 72720
// ALDS1_2_B Selection Sort
import java.io.*;

class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try {  
         int N = Integer.parseInt(br.readLine());
         String[] inputAry = br.readLine().split(" ");
         int[] A = new int[N];
         for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(inputAry[i]);
         }
         selectionSort(A, N);
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static void selectionSort(int[] A, int N) {
      int tmp, minj, cnt = 0;
      for (int i = 0; i < N; i++) {
         minj = i;
         for (int j = i; j < N; j++) {
            if (A[j] < A[minj]){
               minj = j;
            }
         }
         if (i != minj) {
            tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            cnt++;
         }
      }
      for (int i = 0; i < N; i++) {
         if (i == N - 1) {
            System.out.println(A[i]);
         } else {
            System.out.print(A[i] + " ");
         }
      }
      System.out.println(cnt);
   }
}

Measured memory_bytes: 17040
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int h, w, d;
    cin >> h >> w >> d;
    LP pos[SIZE];

    for( LL i = 1; i <= h; ++i ) {
        for( LL j = 1; j <= w; ++j ) {
            LL a;
            cin >> a;
            pos[a] = MP( i, j );

        }
    }
    LL sum[SIZE] = {};

    for( int i = 1; i <= h * w; ++i ) {
        if( i < d ) {
            sum[i] = 0;

        } else {
            sum[i] += sum[i - d] + abs( pos[i - d].F - pos[i].F ) + abs( pos[i - d].S - pos[i].S );

        }

    }

    int q;
    cin >> q;
    for( int i = 0; i < q; ++i ) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;

    }

    return 0;
}



Measured memory_bytes: 3456
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

#define INF 1e9

int main(){
  int n;
  int k;
  cin >> n >> k;
  string s;
  cin >> s;
  int c_2 = 0;
  int c_1 = 0;
  for(int i=0;i<n-1;i++){
    if(s[i] == 'R' && s[i+1] == 'L') c_2 += 1;
  }
  if(s[0] == 'L') c_1 += 1;
  if(s[n-1] == 'R') c_1 += 1;
  int ans;
  ans = n - 2*c_2 + 2*min(c_2,k) - c_1;
  if(k > c_2 && c_1 == 2) ans += 1;
  if(k >= c_2 && c_1 == 0) ans += -1;
  cout << ans << endl;
  return 0;
}


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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	





int main(){
	
	string s;
	
	long long k;

	cin >> s >> k;
	
	int cnt=0;
	int second = 0;
	f(i,0,SZ(s)){
		if(s[i]=='1' && second==0) cnt++;
		
		if(s[i]!='1'){
			second = s[i] - '0';
			break; 
		}
	}
	
	if(cnt>=k){
		cout << 1 << endl;
	}else{
		cout << second << endl;
	}
	
    return 0;
}


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

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

using namespace std;

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

  ll count=0, sum=0;
  rep(i, n){
    sum+=(i+1);
    count++;
    if(sum>=n)break;
  }

  rep(i,count){
    if(i+1==sum-n)continue;
    cout<<i+1<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int num;
	cin>>num;
	int var=num%1000;
	if(var==0)
	 cout<<"0";
    else
	{
		cout<<1000-var;
	}
	return 0;	
}

Measured memory_bytes: 3656
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();
    let d: usize = iterator.next().unwrap().parse().unwrap();

    let l = a + b;
    let r = c + d;

    return if l == r {
        "Balanced".to_string()
    } else if l > r {
        "Left".to_string()
    } else {
        "Right".to_string()
    };
}


Measured memory_bytes: 2144
n, s = [int(i) for i in  raw_input().split()]
weights = []
values = []

for _ in xrange(n):
    w, v = [int(i) for i in raw_input().split()]
    weights.append(w)
    values.append(v)

def knapsack(weights, values, limit):
    n = len(weights)
    # f = [[0 for _ in xrange(limit+1)] for _ in xrange(n)]

    prev = [0 for _ in xrange(limit+1)]

    if weights[0] <= limit:
        for w in xrange(weights[0], limit+1):
            prev[w] = values[0]

    for i in xrange(1, n):
        # print prev
        current = [0] * (limit+1)
        for w in xrange(1, limit+1):
            current[w] = max(prev[w], current[w])
            if weights[i] <= w:
                current[w] = max(current[w], prev[w-weights[i]] + values[i])
        prev = list(current)

    return prev[-1]

# weights = [10, 20, 30]
# values = [60, 100, 120]
print(knapsack(weights, values, s))

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

int main() {

    string b;

    cin >> b;
    if(b == "A"){
        cout << "T" << endl;
    }else if(b == "T"){
        cout << "A" << endl;
    }else if(b == "C"){
        cout << "G" << endl;
    }else if(b == "G"){
        cout << "C" << endl;
    }else{
    }
  return 0;
}

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

int main(void) {
    long long N;
    cin >> N;
    vector< long long > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    vector< pair< long long, long long > > q;
    long long sum = 1;
    for (int i = 1; i < N; i++) {
        if (A[i] == A[i - 1]) {
            ++sum;
        } else {
            q.push_back(make_pair(A[i - 1], sum));
            sum = 1;
        }
    }
    q.push_back(make_pair(A[N - 1], sum));

    long long ans = 0;
    queue< long long > aida;
    aida.push(A[0]);

    for (int i = 1; i < N; i++) {
        ans += aida.front();
        aida.pop();
        aida.push(A[i]);
        aida.push(A[i]);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 9844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	ll n, c, k;
	cin >> n >> c >> k;
	vector<ll> t(n);
	rep(i,n) cin >> t[i];
	int ans = 0;
	sort(ALL(t));
	for(int i = 0; i < n; i++) {
		ll curT = t[i];
		ll limT = curT + k;
		ll cnt = 1;
		while (i + 1 < n && cnt < c && t[i + 1] <= limT) {
			i++;
			cnt++;
		}
		ans++;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 4052
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int mymain(){
  int N, ans;
  ans = 0;
  cin >> N;
  vector<int> v(201);
  for(int i = 0; i < N; i++) cin >> v.at(i);
  while(v.at(N-1) > 1){
    for(int i = 0; i < N; i++) {
    	if(v.at(i) % 2 != 0){
        return ans;
      }
    }
  
    sort(v.begin(), v.end(), greater<int>());
    for(int i = 0; i < N; i++) v.at(i) /= 2;
    ans++;
  }
  return ans;
}

int main(){
  cout << mymain() << endl; 
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val sList = (1..n).map { i -> Pair(i, readLine()!!.split(" ")) }
        .map { pair: Pair<Int, List<String>> -> Pair(pair.first, Pair(pair.second[0], pair.second[1].toInt())) }
        .toTypedArray()
    sList.sortByDescending { pair -> pair.second.second }
    sList.sortBy { pair -> pair.second.first }

    sList.forEach { println("${it.first}") }
}


Measured memory_bytes: 37464
S = list(map(int, input().split(" ")))

if S[0] == S[1] == S[2] and S[0] % 2 == 0:
    print("-1")

else:
    counter = 0

    while True:

        if S[0]%2 != 0 or S[1]%2 != 0 or S[2]%2 != 0:
            print (counter)
            break

        else:
            counter +=1;
            B = list(S)
            S[0] = (B[1]/2) + (B[2]/2)
            S[1] = (B[0]/2) + (B[2]/2)
            S[2] = (B[0]/2) + (B[1]/2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;

int n;
int c;
int k;


vector<int> v;

int main(){
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++){
		int t;
		scanf("%d", &t);
		v.push_back(t);
	}
	sort(v.begin(), v.end());
	
	int cnt = 0;
	
	int bus_cnt = 0;
	int bus_leave = v[0] + k;

	for (int i = 0; i < v.size(); i++){
		if (bus_leave < v[i]){
			cnt++;
			bus_cnt = 0;
			bus_leave = v[i] + k;
		}
		if (bus_cnt == c){
			cnt++;
			bus_cnt = 0;
			bus_leave = v[i] + k;
		}
		bus_cnt++;
	}
	if (bus_cnt){
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

const int limit = 300010;
vector<int> box[limit];
vector<int> ans;

int main(void) {
	int n, a, b;
	cin >> n >> a >> b;

	const int lb = (n + a - 1) / a;


	if (a + b > n + 1 or b < lb) {
		puts("-1");
		return 0;
	}

	int bn = 0;
	rep(i, limit) {
		const int start = a * i + 1;
		if (start > n) break;
		rep(j, a) {
			int cur = a * i + 1 + j;
			if (cur <= n) box[i].push_back(cur);
		}
		bn++;
	}

	const int total = bn;

	rrep(i, total) {
		const int num = min<int>(box[i].size() - 1, b - bn);

		bn += num;
		sort(rbegin(box[i]), rend(box[i]));
		sort(begin(box[i]) + num, end(box[i]));

		for (auto &elem : box[i]) {
			ans.push_back(elem);
		}
	}

	rep(i, n) cout << (i ? " " : "") << ans[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 12528
X,K,D = map(int,input().split())

if abs(X) >= K*D:
  print(abs(X)-K*D)
else:
  n = 1
  while abs(X) > n*D:
    n += 1
  if (K-n)%2 == 0:
    print(abs(abs(X)-n*D))
  else:
    print(abs(abs(X)-(n-1)*D))

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

using namespace std;

string s;
int a[555];
int n;
int K;
int at;


int main() {
    cin >> n >> K;
    int tot = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        tot+=a[i];
    }

    vector<int> divs;
    for(int i = 1; i*i <= tot; i++) {
        if(tot % i == 0) {
            divs.push_back(i);
            divs.push_back(tot/i);
        }
    }
    sort(divs.begin(), divs.end());
    int sz = divs.size();
    sort(a, a+n);
  
    for(int p = 0; p < divs.size(); p++) {

        int j = divs[sz-1-p];
        
        if(tot % j != 0) continue;

        at = j;

        long long tot_extra = 0;
        vector<int> extras;
        for(int i = 0; i < n; i++) {
            tot_extra += (at - (a[i] % at));
            extras.push_back((at - (a[i] % at)));
        }   
        
        sort(extras.begin(), extras.end());
        
        int x = tot_extra/at; // these many subtractions of 'at' needed to make it zero
        
        long long neg = 0;
        
        for(int i = 0; i < x ; i++) {
            // convert from addition to subtraction from largest additions, 
            // that ensures less chance of exceeding K
            neg += (at - extras[n-1-i]);
            tot_extra -= extras[n-1-i];
        }
        if(neg == tot_extra && (neg <= K)) {cout << at; return 0;}
        
    

        
    }


}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Item{
	int value,weight;
	public Item(int weight, int value) {
		this.value = value;
		this.weight = weight;
	}
}

public class Main {


	public static void main(String[] args) {
		Main answer = new Main();
		long solution = answer.solve();
		System.out.println(solution);
	}

	private long solve() {
		Scanner sc =  new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		// from question we know below		 
		int maxValue = N*1000;

		long [][] dp = new long[N+1][maxValue+1];
		long INF = (long)1e9+1;

		for(int i=0;i<=maxValue;i++){
			dp[1][i] = INF;
		}
		Item [] array = new Item[N+1];
		for(int i=1;i<=N;i++){
			array[i] = new Item(sc.nextInt(), sc.nextInt());
		}
		dp[1][array[1].value] = array[1].weight;
		dp[1][0] =0;

		for(int i=2;i<=N;i++){
			for(int j=0;j<=maxValue;j++){
				dp[i][j]= dp[i-1][j];
				if (array[i].value>j) continue;
				dp[i][j] = Math.min(dp[i-1][j-array[i].value]+array[i].weight, dp[i-1][j]);
			}
		}
		long bestValue=0;
		for(int i=0;i<=maxValue;i++){
			if (dp[N][i]<=W) bestValue = Math.max(bestValue, i);
		}
		return bestValue;
	}
}

Measured memory_bytes: 140936
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>

using namespace std;

typedef long long LL;
typedef vector<int> Array;
typedef pair<int, int> P;

const LL LINF = 1LL << 60;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ LL to, cost; edge(int t, LL c) :to(t), cost(c){} };

int main()
{
	int a, b, c;
	while (cin >> a >> b >> c && a)
	{
		int n; cin >> n;
		vector<tuple<int, int, int, int>> inputs;
		vector<int> anses(a + b + c, 2);
		rep(idx, n)
		{
			int i, j, k, r;
			cin >> i >> j >> k >> r;
			i--; j--; k--;
			if (r == 1)
			{
				anses[i] = anses[j] = anses[k] = 1;
			}
			else inputs.emplace_back(i, j, k, r);
		}
		for (auto& t : inputs)
		{
			int i, j, k;
			tie(i, j, k, ignore) = t;

			int normals = 0;
			if (anses[i] == 1) normals++;
			if (anses[j] == 1) normals++;
			if (anses[k] == 1) normals++;

			if (normals != 2) continue;
			if (anses[i] != 1) anses[i] = 0;
			if (anses[j] != 1) anses[j] = 0;
			if (anses[k] != 1) anses[k] = 0;
		}
		rep(i, a + b + c) cout << anses[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> d;
    rep(i, 0, n){
        int h, p;
        cin >> h >> p;
        d.push_back(P(h + p, p));
    } 
    sort(all(d));
    int dp[5010] = {};
    rep(i, 0, 5010) dp[i] = INF;
    dp[0] = 0;
    rep(i, 0, n){
        repb(j, i, 0){
            if(dp[j] != INF && dp[j] <= d[i].first - d[i].second){
                dp[j + 1] = min(dp[j + 1], dp[j] + d[i].second);
            }
        }
    }
    int ans = 0;
    rep(i, 0, n + 1){
        // cout << dp[i] << " ";
        if(dp[i] != INF) ans = i;
    }
    // cout << endl;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int K, A, B;
	cin >> K >> A >> B;

	lint ans = 1;
	if (K < A + 1 || B - A <= 2) ans += K;
	else {
		
		ans += A - 1;
		K -= A - 1;
		ans += 1LL * (B - A) * (K / 2) + (K & 1);
	
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
from sys import stdin
MAX = 10**18

def main():
    line_count = 0

    for line in stdin:
        line_count += 1
        factors_str = line.split()
        if line_count == 2:
            break

    factors = [int(factor) for factor in factors_str]
    
    if 0 in factors:
        print(0)
        return

    product = 1
    for factor in factors:
        product *= factor
        if product > MAX:
            print(-1)
            return

    print(product)

main()

Measured memory_bytes: 23556
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int r;
    cin >> r;

    int s = 3 * r * r;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
inputCount = int(input())

for _ in range(inputCount):

    inputContent = input()
    trainOrder = [item for item in inputContent if str.isalpha(item)]
    directOrder = [item for item in inputContent if item == "<" or item == ">"]

    trainList = trainOrder[0]
    listIndex = 1
    trainLength = 1

    for train, direct in zip(trainOrder[1:], directOrder):

        if listIndex == 1 and direct == "<":
            trainList = train + trainList
            trainLength += 1
        elif listIndex == trainLength and direct == ">":
            trainList += train
            listIndex += 1
            trainLength += 1

        elif direct == "<":
            listIndex -= 1
        else:
            listIndex += 1

    print(trainList)



Measured memory_bytes: 5624
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1e9 + 7;
const int M = 65;
ll dp[M+1][3];

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

    dp[M-1][0] = 1;
    FORR(i,M-1,0) REP(j,3){
        REP(k,3){
            int nex = min(2LL, 2*j + ((n >> i) & 1) - k);
            if (nex >= 0) dp[i][nex] = (dp[i][nex] + dp[i+1][j]) % mod;
        }
    }

    ll ans = 0;
    REP(j,3) ans = (ans + dp[0][j]) % mod;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define boost                         \
    ios_base::sync_with_stdio(false); \
    fin.tie(NULL);                    \
    fout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll, ll>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353
#define PI_2 1.57079632679489661923

int main()
{
    // boost;
    // ifstream fin;
    // fin.open("./fb_d1.txt");
    // ofstream fout;
    // fout.open("./d1_out.txt");

    time_t tic, toc;
    ll tt = 1, n, m, k = 0, i, j, p, q;
    ll a, b, c, h, w, u, v, x, y, t;
    ll l = 0, r = 0;
    ll ans = 0;

    bool poss = true;

    string s;

    // cin >> tt;
    tic = clock();
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> k;

        if(k%2 == 0){
            cout << -1 << nl;
        }
        else{
            if(k%7 == 0) k = k/7;

            ans = 1;
            for(i = 1; i < 10000001; i++){
                if(ans%k == 0) break;
                ans = ((ans%k)*(10%k) + 1)%k;
            }
            if(i == 10000001) cout << -1 << nl;
            else cout << i << nl;
        }
    }
    // fin.close();
    // fout.close();
    // cerr << (clock() - tic*1.0) / CLOCKS_PER_SEC << nl;
    return 0;
}


Measured memory_bytes: 3592
/*
[abc131] F - Must Be Rectangular!
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_XY = 1e5;

int N;
int x[MAX_N], y[MAX_N];
vector<int> g[2 * MAX_XY];
bool visited[2 * MAX_XY];
int cx, cy, ce;

void dfs(int v) {
    if (visited[v]) {
        return;
    }
    visited[v] = true;

    if (v < MAX_XY) {
        cx++;
    } else {
        cy++;
    }
    ce += g[v].size();

    for (int to : g[v]) {
        dfs(to);
    }
}

ll solve() {
    for (int i = 0; i < N; i++) {
        g[x[i]].push_back(y[i] + MAX_XY);
        g[y[i] + MAX_XY].push_back(x[i]);
    }

    ll ans = 0;
    for (int i = 0; i < MAX_XY; i++) {
        cx = cy = ce = 0;
        dfs(i);
        ans += (ll)cx * cy - ce / 2;
    }

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 11008
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    vector<int> A(3); cin >> A[0] >> A[1] >> A[2];
    int K; cin >> K;

    sort(ALL(A));

    REP(i,K) A[2] *= 2;
    cout << A[0] + A[1] + A[2] << endl;
    return 0;
}

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

int main(void)
{
    using namespace std;
    int H, W;
    while (true) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) {
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i == 0 || i == (H - 1)) || (j == 0 || j == (W - 1))){
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 3132
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int a,b,c;
	cin >> a >> b >>c;
	if(b-a==c-b) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)

int func(int n){
  if(n==0)return 1;
  else{
    int t=func(n-1);
    return n*t;
  }
}

int main() {
  int n;
  cin >> n;
  vector<tuple<int,int,int>> a(n);
  rep(i,n){
    get<0>(a[i])=i;
    cin >> get<1>(a[i]) >> get<2>(a[i]);
  }
  
  double ans=0;
  do{
    rep(i,n-1){
      int s= get<1>(a[i])-get<1>(a[i+1]);
      int t= get<2>(a[i])-get<2>(a[i+1]);
      ans+=sqrt(s*s+t*t);
    }
  }while(next_permutation(a.begin(),a.end()));
  cout << fixed << setprecision(10);
  
  cout << ans/(func(n)) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
long long gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
char s[100010],t[100010];
int main()
{
	long long n,m;
	long long g;
	scanf("%lld%lld",&n,&m);
	scanf("%s",s);
	scanf("%s",t);
	g=gcd(n,m);
	long long f=1;
	for(long long i=0;i<g;i++)
	{
		if(s[i*(n/g)]!=t[i*(m/g)])
		{
			f=0;
			break;
		}
	}
	long long ans=n*m/g;
	if(f) printf("%lld\n",ans);
	else printf("-1\n");
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>

using namespace std;


//MAX
#define N 10001
#define Q 501

int main(){


  int n[N];
  int q[Q];

  int num,num2,i,j,count=0;

  //load number
  cin >>num;
  //load data
  for(i=0;i<num;i++){
    cin >>n[i];
  }
  //load number
  cin >>num2;
  //load data
  for(i=0;i<num2;i++){
    cin >>q[i];
  }

  //search
  for(i=0;i<num2;i++){
    for(j=0;j<num;j++){
      //if q[i]=n[j] then count and breal
      if(q[i]==n[j]){
	count++;
	break;
      }
    }
  }
  //print count
  cout <<count<<endl;

  return 0;
}

Measured memory_bytes: 0
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))


ng = 0##ngは常に条件を満たさないように設定
ok = max(logs)##okは常に条件を満たすように設定
while abs(ok-ng)>1:##absをとることで問題ごとにokとngの大小を考えなくてよくなる
  times = 0
  mid = (ok+ng)//2
  for A in logs:
    times += math.ceil(A/mid)-1
    
    
  if times <= K:
    ok = mid##条件を満たすならokを寄せる 
  else:
    ng = mid##満たさないならngを寄せる
    
print(ok)##今回はokそのまま答えだけど普通は添え字


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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int x[60];
ll dp[60][60][3000];
int main(){
	int n,a, mmax = 0;
	cin >> n >> a;
	rep(i,0,n) {
		cin >> x[i];
		mmax = max(mmax, x[i]);
	}
	memset(dp, 0, sizeof(dp));
	dp[0][0][0] = 1;
	int len = n*mmax + 1;
	rep(i,1,n+1) rep(j,0,n+1) rep(k,0,len) {
		if(k<x[i-1]) dp[i][j][k] = dp[i-1][j][k];
		else if(j>=1) dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
	}
	ll ans = 0;
	rep(i,1,n+1) ans += dp[n][i][i*a];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 84608
#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>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i,n) is[s[i]-'a'].insert(i);
    rep(qi,q){
    	int ty;
    	cin >> ty;
    	if(ty == 1){
    		int i; char c;
    		cin >> i >> c;
    		--i;
    		is[s[i]-'a'].erase(i);
    		s[i] = c;
    		is[s[i]-'a'].insert(i);
    	}
    	else{
    		int l, r;
    		cin >> l >> r;
    		--l;
    		int ans = 0;
    		rep(i,26){
    			auto it = is[i].lower_bound(l);
    			if(it != is[i].end() && *it < r) ++ans;
    		}
    		cout << ans << endl;
    	}
    }
    return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define SZ 110000
#define PB push_back
#define MEM(n, val) memset((n), val, sizeof(n))
#define INF 1000000000
#define F first
#define S second
#define MP make_pair
#define LL long long

string s;
int dp[100010][3];

int func(int pos, int past)  {
    if(pos == s.size())    {
        return 0;
    }
    if(dp[pos][past] != -1)    {
        return dp[pos][past];
    }
    int ans = 1000000000;
    if(past == 1)    {
        ///current ta 0 boshbe
        int cc = 0;
        if((s[pos] - '0') == 1)    {
            cc = 1;
        }
        ans = min(ans, cc + func(pos + 1, 0));
    }
    else if(past == 0)    {
        ///current ta 1 boshbe
        int cc = 0;
        if((s[pos] - '0') == 0)    {
            cc = 1;
        }
        ans = min(ans, cc + func(pos + 1, 1));
    }
    else    {
        ///current ta boshiye
        ans = min(ans, func(pos + 1, s[pos] - '0'));

        ///current ta na boshiye
        ans = min(ans, 1 + func(pos + 1, !(s[pos] - '0')));
    }
    return dp[pos][past] = ans;
}

int main()  {
//    freopen("in.txt", "r", stdin);

    cin >> s;
    MEM(dp, -1);
    cout << func(0, 2) << "\n";

    return 0;
}
/**
*/


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i;cin>>N;ll X[N],Y[N];
  REP(i,N){
    ll x,y;cin>>x>>y;
    X[i]=x-y;Y[i]=x+y;
  }
  sort(X,X+N);sort(Y,Y+N);
  cout<<max(X[N-1]-X[0],Y[N-1]-Y[0])<<endl;
  return 0;
}

Measured memory_bytes: 6764
#include<bits/stdc++.h>
using namespace std;
long long ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for (auto & h : H) cin >> h;
    sort(H.begin(), H.end());
    for (int i = 0; i < N; ++i) {
        if (i < N-K) {
            ans += H[i];
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin>>str;
	sort(str.begin(),str.end());
	if(str=="abc"){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

using namespace std;

int a[100001];
const int maxn = 100000;

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int ct[3] = {0, 0, 0};
    int j = 0;
    int ans = 0;
    for (int i = 0; i <= maxn; i++){
        while (j < n && a[j] <= i + 1) {
            if (a[j] == i) ct[1]++;
            else ct[2]++;
            j++;
        }
        ans = max(ans, ct[0] + ct[1] + ct[2]);
        ct[0] = ct[1];
        ct[1] = ct[2];
        ct[2] = 0;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int d; cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int> > s(d);
    rep(i,d)rep(j,26){
        int a; cin >> a;
        s[i].push_back(a);
    }

    vector<int> ld(26,0);

    ll ans=0;
    rep(i,d){
        int t; cin >> t;
        t--;
        ld[t]=i+1;
        ans+=s[i][t];
        rep(j,26){
            ans-=c[j]*(i+1-ld[j]);
        }
        cout << ans << endl;
    }

return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;

//定数
const int MAX_H = 100;
const int MAX_W = 100;
//入力
int H, W;
char field[MAX_H+10][MAX_W+10]; 

void dfs(int x, int y, char c){
    field[x][y] = '.';

    int nx, ny;
    int dx[4] = {-1, 0, 1, 0};
    int dy[4] = {0, 1, 0, -1};
    for (int i=0; i<4;i++){
        nx = x + dx[i];  ny = y + dy[i];
        if (field[nx][ny] == c) {
            dfs(nx, ny, c);
        }
    }
}

int solve(){
    int res = 0;
    char fruits[3] = {'#', '*', '@'};
    for (int i=1; i<=H; i++){
        for (int j=1; j<=W; j++){
            if (field[i][j] == fruits[0]){
                dfs(i, j, fruits[0]);
                res++;
            }else if(field[i][j] == fruits[1]){
                dfs(i, j, fruits[1]);
                res++;
            }else if(field[i][j] == fruits[2]){
                dfs(i, j, fruits[2]);
                res++;
            }
        }
    }

    return res;
}

int main(){
    queue<int> res;

    while (cin>>H && cin>>W && H!=0 && W!=0){
        for (int i=0; i<MAX_H+10; i++){
            for (int j=0; j<MAX_W+10; j++){
                field[i][j] = '.';
            }
        }


        for (int i=1; i<=H; i++){
            for (int j=1; j<=W; j++){
                cin >> field[i][j];
            }
        }
        res.push(solve());
    }

    while (res.size()){
        printf("%d\n", res.front());
        res.pop();
    }

    return 0;
}


Measured memory_bytes: 4228
import java.util.*;

class Main{

    int N,A,B,C;
    int[] Y;

    void solve(){
	Scanner sc = new Scanner(System.in);

	while(true){  
	    N = sc.nextInt();
	    A = sc.nextInt();
	    B = sc.nextInt();
	    C = sc.nextInt();
	    int X = sc.nextInt();
	    if(N==0 && A==0 && B==0 && C==0 && X==0) break;

	    Y = new int[N];
	    for(int i=0; i<N; i++) Y[i] = sc.nextInt();

	    int cnt = 0;
	    boolean notFound = false;
	    for(int i=0; i<N; i++){
		while(true){
		    cnt++;
		    if(X==Y[i]){
			X = (A*X+B)%C;
			break;
		    }
		    X = (A*X+B)%C;

		    if(cnt>10000){
			notFound = true;
			break;
		    }
		}
	    }

	    if(notFound) System.out.println(-1);
	    else System.out.println(cnt-1);
	}
    }

    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 12000